Replace function bugs? 
Author Message
 Replace function bugs?

I have this strange bug in VB6 sp5 with the Replace function. It seems that
the "start" parameter is acting weird.
Let's say I have a string "12312345", I want to replace the 2nd number "3"
with nothing so I end up with "1231245".
I tried Msgbox Replace("12312345","3","",4,1)
The result is: "1245" ??????
It removed the first 3 numbers!

Anyone has an idea why I don't end up with "1231245"?
The Start parameter is supposed to give us the choice of where we want the
search to start, not to take out the first characters.



Tue, 10 Aug 2004 05:29:07 GMT  
 Replace function bugs?
It's documented behaviour (see the end of the Replace functions docs)
"The return value of the Replace function is a string, with substitutions
made, that begins at the position specified by start and and concludes at
the end of the expression string"

It you want to replace a specific character, use a combination of Instr and
Mid, ie

Mid$(strData,InStr(4,strData,"3"),1) = "X"

HTH
--
Chris Anderson
(aka Merak on VISBAS-L)

Quote:
> I have this strange bug in VB6 sp5 with the Replace function. It seems
that
> the "start" parameter is acting weird.
> Let's say I have a string "12312345", I want to replace the 2nd number "3"
> with nothing so I end up with "1231245".
> I tried Msgbox Replace("12312345","3","",4,1)
> The result is: "1245" ??????
> It removed the first 3 numbers!

> Anyone has an idea why I don't end up with "1231245"?
> The Start parameter is supposed to give us the choice of where we want the
> search to start, not to take out the first characters.



Tue, 10 Aug 2004 05:51:16 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Is there a bug in Replace function?

2. Graphics control with point() equivalent function and replace color functions

3. Replace and String.Replace only replaces first occurrence?

4. Bug find & Replace with Word

5. replace bug (VBA 6.0.87)

6. Undefined function 'replace' in expression

7. replace function

8. cross trim function and replace command

9. Replace Function in Access 2000

10. Replace Function

11. replace function quirk when importing text file to Access table

12. VBA6 Replace() function bombing

 

 
Powered by phpBB® Forum Software