Replace Function


Replace Function

Class

Microsoft.VisualBasic.Strings

Syntax

     Dim result As String = Replace(expression, find, replacement _        [, start[, count[, compare]]]) 


expression (required; String)

The complete string containing the substring to be replaced.


find (required; String)

The substring to be found by the function.


replacement (required; String)

The new substring that will replace occurrences of the find substring.


start (optional; Integer)

The character position in expression at which the search for find begins. Any characters before this position are not even returned. If omitted, the search begins with the first character.


count (optional; Integer)

The number of instances of find to replace. If omitted, all instances are replaced.


compare (optional; CompareMethod constant)

The method used to compare find with expression; its value can be CompareMethod.Binary (for case-sensitive comparison) or CompareMethod.Text (for case-insensitive comparison). If omitted, CompareMethod.Binary is used.

Description

The Replace function replaces a given number of instances of a specified substring in another string. The starting position for replacement and a maximum number of replacements can be specified.

Usage at a Glance

  • Setting the replacement argument to an empty string removes all occurrences of find from the original string.

  • The String data type also has a public instance Replace method, which replaces all occurrences of a character or string with another. Its syntax is:

         someString.Replace(oldValue, newValue) 

    where oldValue is a String or Char value containing the text to be replaced, and newValue is a String or Char value containing the replacement text.

See Also

InStr Function, InStrRev Function, Mid Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net