Reputation: 2443
I want to write a simple program in VBScript. In the script I enter data to a variable (string).
After a while I want to enter "\n" but instead of doing an actual \n it prints \n.
How to print special characters
Upvotes: 1
Views: 5437
Reputation: 189457
VBScript supports some constants:-
You will need to use string concatenation to include these characters in a final string
Dim s
s = "First Line"
s = s & vbCrLf & "Second Line"
s = s & vbCrLf & "Third Line"
etc.
If you have a lot of lines this sort of concatenation can get real slow, you can switch to using the Join
function
ReDim a(2)
a(0) = "First Line"
a(1) = "Second Line"
a(2) = "Third Line"
Dim s : s = Join(a, vbCrLf)
Upvotes: 4
Reputation: 38500
You should specify your newline using VBScript constants or the Chr()
function:
What Constant String using Chr Don't use this
------------------- --------- ------------------- ----------------
Carriage return vbCr Chr(13) "\r"
Line feed vbLf Chr(10) "\n"
CR and then LF vbCrLf Chr(13) & Chr(10) "\r\n"
Concatenate that with the string you're trying to split over different lines.
Examples:
s = "First line" & vbCrLf & "Second line"
s = "First line" & Chr(13) & Chr(10) & "Second line"
Upvotes: 1
Reputation: 70314
You have to add it with string concatenation:
mystring = "stuff that comes first" & vbCrLf & "stuff that comes after"
Upvotes: 1
Reputation: 10098
the \n character in vb script is vbcrlf
(vb carriage return line feed ).. its equivalent to \n\r.
here is a simple script.
msgbox "Ping" & VBCRLF & "Pong"
Upvotes: 1