Hi there, I need to replace values in a string with another value, but ignoring the first instance of it i.e. replace the exsisting value with the new value from index 1 onwards. Can anyone tell me the method I should use?
u can use the following code String existing_string = "Hello"; String new_string = existing_string.subString(0,1) + "ow" ; this results in a new string How. "ow" can be raplaced with any other desired string or string object. bye
First, the question seems a little off... to replace values in a string with another value, but ignoring the first instance of it . But then the next bit contradicts this.. from index 1 onwards.
If you are replacing substrings, do you mean from index 1, or from wherever the first instance of your substring ends (all instances after the first)?
In this String, there are three instances of the substring "fg". First occurence is at index 5. To search "from" this point, and replace all other occurences of "fg" with "xx", you'd have to skip index 5 and 6, and start from 7.
All the supplied code does is saves the first letter of your original String and appends an entirely different String.
("axx" is what you'd get with my examples.)
Joined: Feb 06, 2003
hi...........what i thought was he just wants to replace the string with different letters except the first letter and the code also does so... let me know what u need thanx in advance ..........