String

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have the following code line:

myString = myString.Replace("$Name$", Left(myText, InStr(myText, " ") -
1))

I am getting all the text before the first Space in myText and then
replace it in "$Name$"

The problem is that sometimes myText has no space so in that case I
want to get the full text.

Every time this happens I get the error:
Argument 'Length' must be greater or equal to zero.

Could you tell me how to solve this?

Thanks,
Miguel
 
If InStr(myText, " ") > -1 Then

myString = myString.Replace("$Name$", Left(myText, InStr(myText, " ") - 1))

Else : myString = myText

End If
 
Back
Top