Robb Hill
asked on
c# line break not working
I have the following code segement in c#
Each of the < > also inserts text data.
When this renders to the page the \n are included in the output versus breaking the line.
How can I ensure each of these items breaks where I have put the \n?
For extra context here is the code that would fill the < >
public static string ApprovedEmailForNonSAPBody =
@"
Request ID: <RequestID> \n
Requestor: <Requestor> \n
Request Type: <RequestType> \n
Customer: <Customer> \n
Plant: <Plant> \n
Total: <Total> \n
Damages: <Damages> \n
Reason: <Reason> \n
Corrective Action: <CorrectiveAction> \n
Debit Credit Form <testlink>";
Each of the < > also inserts text data.
When this renders to the page the \n are included in the output versus breaking the line.
How can I ensure each of these items breaks where I have put the \n?
For extra context here is the code that would fill the < >
public string GetRejectEmailBody(int requestId)
{
var detailsLink = serverPath + "DrcrRequest/Details/" + requestId;
var drcrRequest = _drcrDbContext.DrCrRequest.FirstOrDefault(x => x.Id == requestId);
var rejectEmailBody = EmailConstants.RejectBody;
var plant = _drcrDbContext.Plants.FirstOrDefault(x => x.PlantId == drcrRequest.PlantId).Name;
var decimalTotal = drcrRequest.DrCrTotal;
var formattedCurrencytotal = String.Format("{0:C}", decimalTotal);
var decimalDamages = drcrRequest.DrCrTotalDowntime;
var formattedCurrncyDamages = String.Format("{0:C}", decimalDamages);
var result = rejectEmailBody.Replace("<RequestID>", requestId.ToString())
.Replace("<RequestType>",
drcrRequest.RequestType.GetDescription()
[(int)drcrRequest.RequestType])
.Replace("<Requestor>", drcrRequest.RequesterName)
.Replace("<Reason>", drcrRequest.Reason)
.Replace("<Customer>", drcrRequest.PayeeCustomerName)
.Replace("<CorrectiveAction>", drcrRequest.CorrectiveActionRequired)
.Replace("<ApproverRole>", getRejectedByRoleName(requestId))
.Replace("<ApproverComments>", getRejectionComments(requestId))
.Replace("<Plant>", plant)
.Replace("<Total>", formattedCurrencytotal)
.Replace("<Damages>", formattedCurrncyDamages)
.Replace("<DetailsLink>", detailsLink);
return result;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I remove the @ cannot I still do the replace on <RequestID>
Please rephrase your last comment, I don't understand what you mean.
ps. Does the adjustment I suggested result in the line breaks you want.
ps. Does the adjustment I suggested result in the line breaks you want.
ASKER
@Andy
I am testing now. I had alot of strings to refactor.
@Alex your scenario kind of works but not not allow for the control needed for dynamic inserts of the string. Not knowing how much text will be there creates a bad display. But thank you for your answer as that clarifes the string difference.
I am testing now. I had alot of strings to refactor.
@Alex your scenario kind of works but not not allow for the control needed for dynamic inserts of the string. Not knowing how much text will be there creates a bad display. But thank you for your answer as that clarifes the string difference.
ASKER
@Andy:
refactoring as suggested...I still get items on same line.
public static string ApprovalBody =
"Request ID: <RequestID> \n " +
"Requestor: <Requestor> \n " +
"Request Type: <RequestType> \n " +
"Customer: <Customer> \n " +
"Plant: <Plant> \n " +
"Total: <Total> \n " +
"Damages: <Damages> \n " +
"Reason: <Reason> \n\n " +
"Corrective Action: <CorrectiveAction> \n\n\n" ;
It still seems that the last two lines...Reason and Corrective action run together....when using the @ if I manually broke 2 or 3 lines it was working. So you can see here i added two line breaks...
Eitherway I was hoping to prevent any runon regardless of how large "REASON" is
refactoring as suggested...I still get items on same line.
public static string ApprovalBody =
"Request ID: <RequestID> \n " +
"Requestor: <Requestor> \n " +
"Request Type: <RequestType> \n " +
"Customer: <Customer> \n " +
"Plant: <Plant> \n " +
"Total: <Total> \n " +
"Damages: <Damages> \n " +
"Reason: <Reason> \n\n " +
"Corrective Action: <CorrectiveAction> \n\n\n" ;
It still seems that the last two lines...Reason and Corrective action run together....when using the @ if I manually broke 2 or 3 lines it was working. So you can see here i added two line breaks...
Eitherway I was hoping to prevent any runon regardless of how large "REASON" is
ASKER
It seems that putting the \n\n after Reason and making to string was the best solution. That section was inserting a max 5000 character limit. My test was successful.
Thank you both for you help and knowledge on this subject.
Thank you both for you help and knowledge on this subject.
ASKER
Doing it the way you suggest if I do this...many times the lines run together...then if I change Corrective Action to CorrectiveAction it works. I am not sure how to make sense of this but I do need to esure nice formatting as this is used as the body of an email to customers.
Reason: <Reason>
Corrective Action: <CorrectiveAction>