Siebel VB Language Reference > Methods Reference for Siebel VB > String Methods >

Replace String Method


The Replace String method replaces part or all of one string with another string. It returns the string that the stringVar argument contains.

Format

Mid (stringVar, start[, length]) = string

The following table describes the arguments that you can use with this method.

Argument
Description

stringVar

The string that this method modifies.

start

An integer that identifies the position in stringVar at which to begin replacing characters. The position of the first character in a string is 1.

length

An integer that identifies the number of characters to replace.

string

The string that this method places into stringVar.

Usage

This method replaces characters starting at the start position to the end of the string in the following situations:

  • You do not include the length argument.
  • The string that the string argument contains is shorter than the value that the length argument contains.

This method does the following:

  • If the start value is larger than the number of characters in stringVar, then it appends the string that the string argument contains to stringVar.
  • If length plus start is greater than the length of stringVar, then it replaces characters only up to the end of stringVar.
  • If the value in the start argument is greater than the number of characters that exist in stringVar, then it creates an error at runtime.

The Replace String method never modifies the number of characters in the stringVar argument.

Example

The following example replaces the last name in a custom string with asterisks (*):

Sub Button_Click
   Dim username as String
   Dim position as Integer
   Dim count as Integer
   Dim uname as String
   Dim replacement as String
   username = "Chris Smith"
   uname = username
   replacement = "*"
   Do
      position = InStr(username," ")
      If position = 0 then
         Exit Do
      End If
      username = Mid(username,position + 1)
      count = count + position
   Loop
   For x = 1 to Len(username)
      count = count + 1
      Mid(uname,count) = replacement
      Next x
End Sub

Siebel VB Language Reference Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Legal Notices.