I am working with strings in C#. I have a string like,
StringBuilder sb = new StringBuilder();
sb.AppendLine(ValidatorMethod1());
sb.AppendLine(ValidatorMethod2());
after "sb" is called on ValidatorMethod1(), I call a ValidatorMethod2() as shown, both returns a error message as a string based on a condition. If ValidatorMethod1() and ValidatorMethod2() returns a error msg, then all is fine. But if ValidatorMethod2() fails, then the length of the error message returned from ValidatorMethod2() is "0", but still a line is appended with "sb" and thus a empty error line is appended after ValidatorMethod1()'s error msg.
I tried googling, but links like:
- How to insert newline in string literal? did not help me.
So please can anyone give a idea to, "put the returned string in newline if its length is greater than zero" or do nothing?
EDIT:
Hi All, I guess I dint get the proper solution for which I am lookin for. I do not want to append line after each "sb". But if I have a error msg, then, I want to put in NEWLINE.. Can someone give me a different solution which caters to my need?..