开发者

Special characters

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


VBScript supports some constants:-

  • vbLf equivalent to "\n"
  • vbCr equivalent to "\r"
  • vbCrLf equivalent to "\r\n"

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)


You have to add it with string concatenation:

mystring = "stuff that comes first" & vbCrLf & "stuff that comes after"


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"


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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜