Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Daan_M
182 Views, 2 Replies

Replacing specific characters of a string

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.

Daan_M
in reply to: Daan_M

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

 

oVar2 = replace(oVar2, "xxx", oVarSize)
m_baczewski
in reply to: Daan_M

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)