Discussion:
Simple Question: Newline = Chr(13)???
(too old to reply)
Mark Watkins
2004-02-02 21:04:29 UTC
Permalink
I have a string and I want to insert a newline/return into the string. I
thought
Chr(13) would do it, but I guess not.

'is this what I should be doing?
myString = "something " & Chr(13) & " something else"
Richard Mueller [MVP]
2004-02-02 21:17:13 UTC
Permalink
Post by Mark Watkins
I have a string and I want to insert a newline/return into the string. I
thought
Chr(13) would do it, but I guess not.
'is this what I should be doing?
myString = "something " & Chr(13) & " something else"
Hi,

I use vbCrLf, one of the constants built into WSH. It is equivalent to
Chr(13) & Chr(10) (a carriage return and a line feed).

myString = "something" & vbCrLf & "something else"
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
MikeB
2004-02-02 21:22:31 UTC
Permalink
Post by Mark Watkins
I have a string and I want to insert a newline/return into the string. I
thought
Chr(13) would do it, but I guess not.
'is this what I should be doing?
myString = "something " & Chr(13) & " something else"
msgbox "something " & vbCrLf & " something else"
msgbox "something " & Chr(13) & Chr(10) & " something else"
msgbox "something " & Chr(13) & " something else"

'All three are the same
Jens Lenge
2004-02-02 22:38:48 UTC
Permalink
Post by MikeB
msgbox "something " & vbCrLf & " something else"
msgbox "something " & Chr(13) & Chr(10) & " something else"
msgbox "something " & Chr(13) & " something else"
'All three are the same
I tend to rather use the vbNewLine constant for that, because it is in
general system dependent if a newline is just a Chr(13) or a vbCrLf =
Chr(13)+Chr(10).

According to the VBS documentation, the vbNewLine constant is equivalent to
either just Chr(13) or Chr(13)+Chr(10), depending on what the target system
expects as a newline marker.
Steve Fulton
2004-02-03 13:31:37 UTC
Permalink
Post by MikeB
Post by Mark Watkins
I have a string and I want to insert a newline/return into the string. I
thought
Chr(13) would do it, but I guess not.
'is this what I should be doing?
myString = "something " & Chr(13) & " something else"
msgbox "something " & vbCrLf & " something else"
msgbox "something " & Chr(13) & Chr(10) & " something else"
msgbox "something " & Chr(13) & " something else"
'All three are the same
All three *appear* the same because of the way Windows handles bare carriage
return characters in dialogs. That all three are *not* the same can be
demonstrated by changing MsgBox to WScript.echo and using cscript.exe to run the
script in a command prompt window.
--
Steve

Don't wrestle with pigs. You both get dirty and the pig likes it. -Mark Twain
Loading...