escape character not working in string

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

I have the following code

Dim val As Int16 = 7
Dim name As String = "Mr. John"
Dim num As Double = 45.06F
Dim str As String = String.Format("Days Left : {0}. Current DataTime: {1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)
Console.WriteLine(str)

The line should break before the "String:", but it doesn't and displays
showing the "\n".

Why doesn't it break at the \n?

Thanks,

Tom
 
Because VB.Net does NOT have any such escape sequences.

Replace the \n with {4} and add Environment.Newline to you parameter list
instead.
 
tshad said:
Dim str As String = String.Format("Days Left : {0}. Current DataTime:
{1:u}.
\n String: {2}, Float: {3}", val, DateTime.Now, name, num)
Console.WriteLine(str)

The line should break before the "String:", but it doesn't and displays
showing the "\n".

'"... {1:u} " & ControlChars.NewLine & " String: {2}..."'.
 
Herfried said:
'"... {1:u} " & ControlChars.NewLine & " String: {2}..."'.

Note:

The ControlChars.NewLine is the newline string used in dos/windows
systems, the same as ControlChars.CrLf. The Environment.NewLine propery
returns the appropriate newline string regarless of system.
 
Back
Top