Replace a letter in a string

  • Thread starter Thread starter Dinko Deranja
  • Start date Start date
D

Dinko Deranja

Suppose that you have a string e.g. "delicious" and an integer e.g. 5. How
to
replace the character at position 5 with next character (in position 6) so
that "delicious" becomes "deliicous" ?
 
I suggest that :

Dim myWord As String = "delicious"

Dim myWordInChar As Char() = myWord.ToCharArray()

Dim tmp As Char = myWordInChar(4)

myWordInChar(4) = myWordInChar(5)

myWordInChar(5) = tmp

myWord = New String(myWordInChar)
 
I go for

dim a as string = "delicious"
dim b as string = a.substring(0,4) & a.substring(3)

Cor
 
Back
Top