可以要正则表达式来进行替换,给你个简单的例子,具体的你再查查API。
[CODE]import java.util.*;
import java.util.regex.*;
public class RegTest
{
public static void main(String args[])
{
String patternString="C#";
String replacement="Java";
String text="C# is very good! I like C#!";
Pattern pattern=null;
try
{
pattern=Pattern.compile(patternString,Pattern.CASE_INSENSITIVE);
Matcher matcher=pattern.matcher(text);
if(matcher.find())
{
String output=matcher.replaceAll(replacement);
System.out.println(output);
}
else
System.out.println("No match");
}catch(Exception e){}
}
}[/CODE]