Find a number then replace characters before it in a string
Posted on 2003-10-24
I have a textbox that contains something like "blablablabla777.JPG". I'm trying find the first number in that string and them replace whatever is before the first number with the text "slide", so that It would say "slide777.JPG". For some reason, the code that I have finds the last number in "blablablabla777.JPG", then it replaces whatever is before that last "7" including the two 7s before it. Here's the code:
Private Sub Command1_Click()
For i = 1 To 9
pos = InStr(Text1.Text, i & ".JPG")
If (pos <> 0) Then
charsToReplace = Mid(Text1.Text, 1, pos - 1)
Text1.Text = Replace(Text1.Text, charsToReplace, "slide")
Can you guys please help?
Thanks in advance.