Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I replace a character in a string?

String Manipulation

How do I replace a character in a string?

by  swilliams  Posted    (Edited  )
Use the built in Replace VB function to replace any occurrence of one string or set of characters in a string with any other string or set of characters.

The syntax for the Replace function is:

Replace(string being manipulated, unwanted characters, alternative characters)

where unwanted characters are the characters (may only be one character, eg " or ') that you want to remove from your string, and alternative characters are the characters (again may only be one character, like a space) to be used in place of the unwanted characters.

So, if you have a variable, sString say, that holds the string [color blue]He said, "Hello".[/color] and you want to replace the double quotes with single quotes, then you would use the following line:

[color blue]sString = Replace(sString, Chr(34), Chr(39))[/color]

transforming sString to [color blue]He said, 'Hello'.[/color]

Here Chr(34) is a double quote and Chr(39) is a single quote.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top