49

I want to use the Replace function in VBScript to replace all line breaks in a string for "\n". I come from Java, so using \n inside a string means a line break.

Is there an equivalent in VBScript?

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
Carlos Blanco
  • 8,592
  • 17
  • 71
  • 101

6 Answers6

54

For replace you can use vbCrLf:

Replace(string, vbCrLf, "")

You can also use chr(13)+chr(10).

I seem to remember in some odd cases that chr(10) comes before chr(13).

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
Fionnuala
  • 90,370
  • 7
  • 114
  • 152
16

This page has a table of string constants including vbCrLf

vbCrLf | Chr(13) & Chr(10) | Carriage return–linefeed combination

ChrisF
  • 134,786
  • 31
  • 255
  • 325
10

As David and Remou pointed out, vbCrLf if you want a carriage-return-linefeed combination. Otherwise, Chr(13) and Chr(10) (although some VB-derivatives have vbCr and vbLf; VBScript may well have those, worth checking before using Chr).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
6

Tried and tested. I know that this works:

Replace(EmailText, vbNewLine, "<br>")

i.e. vbNewLine is also the equivalent of \n

4

I think it's vbcrlf.

replace(s, vbcrlf, "<br />")
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
David
  • 3,519
  • 1
  • 24
  • 30
4

I had to use vbLf only in an ASP script where the original data was POSTed from a PHP script on a cPanel box over to ASP on a win server

(VBScript)

EmailText = Replace(EmailText, vbLf, "<br>")
Rit Man
  • 51
  • 2