Question Help with .Replace

jzq

New member
Joined
Jan 15, 2011
Messages
2
Programming Experience
Beginner
Basically I want to use .Replace for a filename but the problem is this

filename: File
target name: Fils

So I want to do filename.Replace("e","s").Replace("s","p")..... etc...

actual name after replace: Filp

So it would replace the first e with an s, but then it replaces it again with a p... as it changes the string and then continues the .Replace's...

anyway around this using .replace...

thanks
 
Get the chars array and loop through it, only doing one replace operation on each char.
 
not sure that will work as i dont know what the character will be so have to do all replaces... so when the first replace happens it then needs to go on to the next character and start the replaces again... It needs to go to the next character after doing the first replace.

anyway, in the end i just did it by taking 2 character arrays and filling them like:

charArray1 = a, b, c, d, e, f...
charArray2 = b, e, f, g, h, p...

then looped through each character in my string to find its position in charArray1, then filled a new array with the value of charArray2 at the position found in charArray1.
so if my string was "abc", it would find "a" at charArray1(index 0)
so append charArray2(0) to charArray3
so charArray3 ends up with "bef"...

works but didnt think it was that efficient....
 
Back
Top