Strings
Author |
Message |
BoXxI2004
|
Posted: Tue Mar 09, 2004 1:48 pm Post subject: Strings |
|
|
i am making a program where the user enters a sentance, a word to be replace and a new word to be replaced with.
for ex : Hello , how are you
i want to replace the letter o with silly it would become
Hellsilly, hsillyw are ysillyu
u cant use the direct method where u use .replace... but i know the algoruthm where u pull the words apart.... but i am having trouble with sticking the new word in... meaning i dont know how to not include the letter .. and put in the new word. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Tue Mar 09, 2004 1:58 pm Post subject: (No subject) |
|
|
Hmmm...
code: | String initial = "hello how are you?";
initial.replaceAll("o", "silly"); |
|
|
|
|
|
 |
BoXxI2004
|
Posted: Tue Mar 09, 2004 3:16 pm Post subject: (No subject) |
|
|
u cant use the shortcut.. ie "replace"... u have to go about using the long method of using index og, and substrings.... how do u do that.. |
|
|
|
|
 |
Tony

|
Posted: Tue Mar 09, 2004 5:15 pm Post subject: (No subject) |
|
|
bah, always with the long methods
so you just run a forloops checking all the substrings the size of template to be replaced... if the substring matches the template, then replace it with replacement string |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|
|