I am trying to make a method that replaces words. It uses a tokenizer to check all of the strings against the first short string, if it finds a match then it changes the word to the second string entered. I have everything working except I dont know how to modify a string to place the new word where the old one was. I couldnt work out which would be easier to use, a tokenizer or a string. Help with either would be great ty.
if I understand your post right, you can use a StringBuffer inside the loop, for each token, append the original sub-string if it does not match the first short string or append the 2nd string if a match found. then call toString() to convert the StringBuffer to String.
not so smart guy still curious to learn new stuff every now and then
Once you have all those substringing things down, you can put the last three lines into one, or leave them separate for clarity.
BTW: It's common practice in this forum to give vague answers that invite you do to some homework on the APIs. Lemme know if that was TOO vague or just enough to have some fun with the JavaDoc. Also feel free to post the code you have running (or almost running) for more specific comments.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Mar 25, 2004
K guys thanks, im using the orignal tokenizer idea, however now it says that the StringTokenizer class isnt correct, ive checked the spelling and my sytanx alright which package is it in?
Originally posted by Peter Shipway: K guys thanks, im using the orignal tokenizer idea, however now it says that the StringTokenizer class isnt correct, ive checked the spelling and my sytanx alright which package is it in?