Computer Science Canada

Strings

Author:  BoXxI2004 [ 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.

Author:  wtd [ Tue Mar 09, 2004 1:58 pm ]
Post subject: 

Hmmm...

code:
String initial = "hello how are you?";
initial.replaceAll("o", "silly");

Author:  BoXxI2004 [ Tue Mar 09, 2004 3:16 pm ]
Post 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..

Author:  Tony [ Tue Mar 09, 2004 5:15 pm ]
Post subject: 

bah, always with the long methods Rolling Eyes

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


: