line feed and tab

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have a C# app that I am writing which is going to insert text into a
table, which is then picked up by another program and emailed. On the text
version of the email (when the user doesn't have html email), I need to put
tabs in between columns of data and then line feeds after each row. How can
I do this? Right now I'm doing "\t" for tab and "\r\n" for line feed, but
when I generate the text, those characters actually come out in the text.

Please help.
Mark
 
Mark,

Instead of escape sequences you could also use explicit type casting.
To insert a horizontal tab, you would then simply use (char) 9

Hope this helps.

Regards,
Alex
 
Could you show some code for the portion where you generate your text
version of the email? One way could certainly be to substitute the verbatim
escape sequences with the appropriate formatting characters.
 
Okay, I've tried it both of these ways and get the same result.

string strText="Property Name" + (char)9 + "Address" + (char)9 +
"City/State/Zip";
OR
string strText="Property Name" + "\t" + "Address" + "\t" + "City/State/Zip";
 
Mark,

Escape sequences are only interpreted when doing some sort or "Formatted"
operation such as writing to the Console or a file, or in the case of the
StringBuilder, AppendFormat().

To insert formatting characters into a string, try the following:
StringBuilder sb = new StringBuilder();

sb.Append("Text...");

sb.AppendFormat("\t\t");

sb.Append("More Text");

sb.AppendFormat("\r\n");

sb.Append("New Line");

Console.WriteLine( sb.ToString () );

Dan
 
Back
Top