how to replace all the stoping words?

Hi Guys!

I need your guy抯 suggestion. I am writing a code using regex. My motive it so replace the entire stopping words with 憇pace character? I use pattern and matchers. I wrote a piece of code, which works fine. But my program works for just one words. Wherever I find 慶at?I replace it with 慸og? Now let say if I have a big String or may be a file and I want to replace all the stopping words in it. Do I have to create a whole bunch of patterns and matcher to replace the words? OR is there any other way to do it? Like most of the things here is a catch, I don抰 want to use String because of speed.

Here is my code

Pattern p = Pattern.compile("cat",Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher("one cat two CATs in the yard");

StringBuffer sb =new StringBuffer();

while (m.find()){

m.appendReplacement(sb,"dog");

}

m.appendTail(sb);

System.out.println(sb.toString());

Thanks alot in Advance

[1175 byte] By [asyed01a] at [2007-11-27 6:08:23]
# 1
what is "Stopping words" mean ?
eaajea at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 2

import e.util.*;

import java.util.*;

import java.util.regex.*;

/**

* For Rewriter see http://elliotth.blogspot.com/2004/07/java-implementation-of-rubys-gsub.html

*/

class Replacer extends Rewriter

{

public Replacer()

{

super("(?i)(cat|pig)");

}

public String replacement()

{

final String newValue = replacements_.get(group(1));

return Matcher.quoteReplacement((newValue == null) ? group(0) : newValue);

}

public void putReplacement(String key, String value)

{

replacements_.put(key, value);

}

private final Map<String, String> replacements_ = new HashMap<String, String>();

}

public class Fred906_1

{

public static void main(String[] args) throws Exception

{

String fileContent = "The quick brown cat jumps over the lazy pig.";

Replacer macroProcessor = new Replacer();

macroProcessor.putReplacement("cat","fox");

macroProcessor.putReplacement("pig","dog");

System.out.println(macroProcessor.rewrite(fileContent));

}

}

sabre150a at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 3
> I don抰 want to use String because of speed.I think using String (or StringBuilder) is faster than using regular expressions, not?
tom_jansena at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 4
> I don抰 want to use String because of speed.Explain why you think speed is going to be an issue, please.
Hippolytea at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 5
Hi FoxSorry for late replay.Yes that抯 what we have discuss that Sting might be slower in speed as compare to regex. Because of iteration. I will take more time as compare to regex (regular expression). Isn抰 it? Please lemme know if this is not the case.
asyed01a at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 6

Who knows or cares unless speed turns out to be a problem. Suck it and see.

In my experience, simple RE's (those without look-aheads and look-behinds) are faster than there equivalent series of raw string comparisons... simply because the guys who write RE engines are smarter than me :-)

Keith.

corlettka at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...
# 7
lol cool.. so i will stuck with String,
asyed01a at 2007-7-12 17:10:38 > top of Java-index,Java Essentials,New To Java...