ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • <ANSI string>.Replace and UNICODE
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Replaces all occurrences of a specified substring in a string with another specified substring.
Note: The initial character string is not modified.
New in version 2025
WEBDEV - Browser code The syntax for replacing a set of strings with a new string is now available.
WEBDEV - Browser code The syntax for replacing a part of a string with a new string is now available.
Example
ChaîneInitiale is string = "Abracadabra !"
ChaîneRemplacée is string = ChaîneInitiale.Replace("a", "o")
Info(ChaîneRemplacée) // Affiche "Abrocodobro !"
WINDEVWEBDEV - Server codeiPhone/iPadIOS WidgetApple WatchMac Catalyst
ChaîneInitiale is string = "betterave // abricot // fraise / melon \ noix / citron"
ChaîneRemplacée is string = ChaîneInitiale.Replace(["//", "/", "\", "\\"], "-")
Trace(ChaîneRemplacée) // Affiche "betterave - abricot - fraise - melon - noix - citron"


tabMonTableau is array of 4 strings 
tabMonTableau[1] = "//"
tabMonTableau[2] = "/" 
tabMonTableau[3] ="\"
tabMonTableau[4] = "\\"
ChaîneRemplacée = ChaîneInitiale.Replace(tabMonTableau, "-")
Trace(ChaîneRemplacée) // Affiche "betterave - abricot - fraise - melon - noix - citron"
WINDEVWEBDEV - Server codeiPhone/iPadIOS WidgetApple WatchMac Catalyst
ChaîneInitiale is string = "betterave // abricot // fraise / melon \ noix / citron"
ChaîneRemplacée is string = ChaîneInitiale.Replace(["//", "/", "\", "\\"], "-")
Trace(ChaîneRemplacée) // Affiche "betterave - abricot - fraise - melon - noix - citron"


tabMonTableau is array of 4 strings 
tabMonTableau[1] = "//"
tabMonTableau[2] = "/" 
tabMonTableau[3] ="\"
tabMonTableau[4] = "\\"
ChaîneRemplacée = ChaîneInitiale.Replace(tabMonTableau, "-")
Trace(ChaîneRemplacée) // Affiche "betterave - abricot - fraise - melon - noix - citron"
Syntax

Replacing a string with another string Hide the details

<Result> = <Initial string>.Replace(<String to replace> , <New string> [, <Option>])
<Result>: Character string
New string in which the specified strings have been replaced.
<Initial string>: Character string
Character string in which replacements are to be made (maximum size: 2 GB).
<String to replace>: Character string
String to be replaced in the initial string.
If this parameter corresponds to an empty string (""), <Result> will correspond to <Initial string>.
<New string>: Character string
String that will replace <String to replace>.
If this parameter corresponds to an empty string (""), all the occurrences of <String to replace> will be deleted.
<Option>: Optional constant (or combination of constants)
Indicates the characteristics of the search for the word to replace:
IgnoreCaseCase and accent insensitive search (ignores uppercase and lowercase differences).
WholeWordWhole word search (enclosed in punctuation characters or spaces)

By default, the search is case sensitive: the string searched for must have the same case as the string to be found in the initial string.. To perform a case-insensitive search, use the IgnoreCase constant.
New in version 2025
WEBDEV - Browser code This parameter is now available.
WINDEVWEBDEV - Server codeiPhone/iPadIOS WidgetApple WatchMac Catalyst

Replacing a set of strings with a new string Hide the details

<Result> = <Initial string>.Replace(<Array of strings to replace> , <New string> [, <Option>])
<Result>: Character string
New string in which the specified strings have been replaced.
<Initial string>: Character string
Character string in which replacements are to be made (maximum size: 2 GB).
<Array of strings to replace>: Array
Array of strings to be replaced in <Initial string>. This array can correspond to:
  • an Array variable.
  • an array in the following format: [Value1, Value2, ... , Value N].
If this parameter corresponds to an empty string (""), <Result> will correspond to <Initial string>.
<New string>: Character string
String that will replace all the strings specified in <Array of strings to replace>.
If this parameter corresponds to an empty string (""), all the occurrences of <String to replace> will be deleted.
<Option>: Optional constant (or combination of constants)
Indicates the characteristics of the search for the words to replace:
IgnoreCaseCase and accent insensitive search (ignores uppercase and lowercase differences).
WholeWordWhole word search (enclosed in punctuation characters or spaces)

By default, the search is case sensitive: the string searched for must have the same case as the string to be found in the initial string.. To perform a case-insensitive search, use the IgnoreCase constant.
WINDEVWEBDEV - Server codeiPhone/iPadIOS WidgetApple WatchMac Catalyst

Replacing part of string with a new string Hide the details

<Result> = <Initial string>.Replace(<Position> , <Length> , <New string>)
<Result>: Character string
New string in which the specified part of string has been replaced.
<Initial string>: Character string
Character string to be replaced (maximum size: 2 GB).
<Position>: Integer
Position of the part of string to replace.
<Length>: Integer
Length of the part of string to replace.
<New string>: Character string
String that will replace the specified part of string.
Remarks

<ANSI string>.Replace and UNICODE

<Initial string>, <String to replace> and <New string> can correspond to:
  • ANSI strings.
  • or Unicode strings.
  • buffers.
You have the ability to use ANSI strings, Unicode strings and buffers in the different parameters of the function.
The following conversion rule is used for the Ansi systems (Windows or Linux):
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • If the first condition is not met and there is at least one Unicode string, all the strings are converted to Unicode and the operation is performed in Unicode (the conversion is performed with the current character set, if necessary).
  • Otherwise, the operation is performed in Ansi.
The conversion rule used for Unicode systems is as follows:
  • If at least one of the strings is a buffer, all the strings are converted to buffers and the operation is performed with buffers.
  • Otherwise, the operation is performed in Unicode.
For more details on Unicode, see Unicode management.
Reminder: The language parameters used are defined when the ChangeCharset function is called.
Component: wd300vm.dll
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/17/2024

Send a report | Local help