Putting a newlines and quotes in strings

divil
01-05-2002, 04:14 PM
Ok, firstly, a common question. How do you put newline characters in string? In Windows, a new line is represented by a carriage return (ASCII code 13) and then a line feed (ASCII code 10).

myString = "line 1" & vbCrLf & "line 2"

Will have the effect of splitting the string in to two lines when rendered in Windows.

To put double quotes in a string, you can use two double quotes next to each other. For example, to create a string with one quote in it:

myString = """"

Or, to have a string where a word is enclosed by quotes:

myString = "The word ""amazing"" is enclosed in quotes."

This method works well for some people, but others (like myself) think this makes strings look somewhat messy, with "'s thrown around everywhere. The alternative is to concatenate the string using Chr$(34). 34 is the ASCII code for a double quote:

myString = "The word " & Chr$(34) & "amazing" & Chr$(34) & " is enclosed in quotes."

Here endeth the lesson.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum