Replacing specific characters of a string

Replacing specific characters of a string

Daan_M
Collaborator Collaborator
216 Views
2 Replies
Message 1 of 3

Replacing specific characters of a string

Daan_M
Collaborator
Collaborator

Hi,

 

I have a string variable in format: [Name]_xxx_[Something else]

And another string variable called size : "999"

 

I want to replace the "xxx" with the size variable, but i can't get it to work.

I tried the following:

 

Dim oVar2 As String = GoExcel.CellValue(oExcel, "Blad1", "D" & oSubCellCount) 

'Gives output: "EUA_xxx_A"

Dim oVarSize As String 	= GoExcel.CellValue(oExcel, "Blad1", "B" & oCellCount) 

'Gives output: "025"

Replace(oVar2, "xxx", oVarSize)

Msgbox(oVar2)

'Still gives output "EUA_xxx_A" and not the desired "EUA_025_A"

 

i also tried without succes:

oVar2.replace("xxx", oVarSize)

 

The solution is probabably pretty simple, but an explanation of what i do wrong is appreciated.

0 Likes
217 Views
2 Replies
Replies (2)
Message 2 of 3

Daan_M
Collaborator
Collaborator

Found it, i needed to assign the change to the string variable itself:

 

oVar2 = replace(oVar2, "xxx", oVarSize)
0 Likes
Message 3 of 3

m_baczewski
Advocate
Advocate

Hi @Daan_M 

You should assign a variable in my case its newString, but you can assign oVar1 as newString

oVar1 = "EUA_xxx_A"
oVarSize = "025"

newString = Replace(oVar1, "xxx", oVarSize)

Logger.Info(newString)

 

0 Likes