escape character not working in string


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
 
Ad

Advertisements

S

Stephany Young

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

Replace the \n with {4} and add Environment.Newline to you parameter list
instead.
 
H

Herfried K. Wagner [MVP]

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}..."'.
 
Ad

Advertisements

?

=?windows-1252?Q?G=F6ran_Andersson?=

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top