Logo

Programming-Idioms

History of Idiom 63 > diff from v50 to v51

Edit summary for version 51 by zqwnvl:
New VB implementation by user [zqwnvl]

Version 50

2021-03-25, 17:52:34

Version 51

2021-08-19, 06:32:40

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Idiom #63 Replace fragment of a string

Assign to x2 the value of string x with all occurrences of y replaced by z.
Assume occurrences of y are not overlapping.

Variables
x2,x,y,z
Variables
x2,x,y,z
Extra Keywords
substring substitute
Extra Keywords
substring substitute
Imports
Imports System
Code
Dim x2 = x.Replace(y, z, StringComparison.Ordinal)
Comments bubble
It is best practice to explicitly specify the string comparison method when working with strings in .NET.
Doc URL
https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings
Origin
https://docs.microsoft.com/en-us/dotnet/api/system.string.replace
Demo URL
https://sharplab.io/#gist:1d91331e52756c25ebaac1d01d9b8d53