你的问题好简单,我给你个函数,可以将你的bb替换成任何东东
str=replacetag(str,"bb","2313231123!@!@@!#!@#$$%%$^\");public static String replacetag(String in_str,String in_tag,String repalace_text)
{
 StringBuffer in_str_buffer=new StringBuffer(in_str);
 int site;
 site=in_str.indexOf(in_tag);
if (site!=-1) in_str_buffer=in_str_buffer.replace(site,site+in_tag.length(),repalace_text);
 in_str=in_str_buffer.toString();
 return in_str;
}

解决方案 »

  1.   

    有标准函数可用String replaceAll(String regex, String replacement) 
              Replaces each substring of this string that matches the given regular expression with the given replacement. Str.replaceAll( "BB", "12" );
      

  2.   

    好象来晚了点。String replaceAll(String regex, String replacement) 
              Replaces each substring of this string that matches the given regular expression with the given replacement.
      

  3.   

    呵是啊,是来晚了。
    replaceAll
    public String replaceAll(String regex,
                             String replacement)
    Replaces each substring of this string that matches the given regular expression with the given replacement. 
    An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
    regex - the regular expression to which this string is to be matched 
    Returns:
    The resulting String 
    Throws: 
    PatternSyntaxException - if the regular expression's syntax is invalid 
    NullPointerException - if regex is null
    Since:
    1.4 
    See Also:
    Pattern
      

  4.   

    bluerain2002(蓝雨灰天) (  ):String 类中已经有replaceAll这个方法拉
    ublic String replaceAll(String regex,
                             String replacement)Replaces each substring of this string that matches the given regular expression with the given replacement.An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)
    Parameters:
    regex - the regular expression to which this string is to be matched
    Returns:
    The resulting String
    Throws:
    PatternSyntaxException - if the regular expression's syntax is invalid
    NullPointerException - if regex is null
    Since:
    1.4See Also:
    Pattern不过要熟悉正则表达式
      

  5.   

    jdk1.4 有现成的替换方法,1.3只能自己去想办法咯
      

  6.   

    nod,jdk1.4easy,如果是1.3,需要自己设计函数,不过也简单,递归替换就行
      

  7.   

    public String stringReplace(String sourceString, String toReplaceString, String replaceString)
      {
        String returnString = sourceString;
        ArrayList arrayList = new ArrayList();
        int stringLength = 0;
        if(toReplaceString != null)
        {
          stringLength = toReplaceString.length();
        }
        if(returnString != null && returnString.length() > stringLength)
        {
          int max = 0;
          String S4 = "";
          for(int i = 0; i < sourceString.length(); i++)
          {
            max = i + toReplaceString.length() > sourceString.length()? sourceString.length():i + stringLength;
            String S3 = sourceString.substring(i, max);
            if(!S3.equals(toReplaceString))
            {
              S4 += S3.substring(0,1);
            }
            else
            {
              S4 += replaceString;
              i += stringLength -1 ;
            }
          }
          returnString = S4;
        }
        return returnString;
      }
      

  8.   

    你可以把字符串定义为StringBuffer型,用它的replace(int&nbsp;start,int&nbsp;end,String&nbsp;str)方法。
    例如:
    StringBuffer strBuf = new StringBuffer().append("AABBCCAABBCCAABBCC");
    //例如要将第二个BB换成12
    int index = -2;
    for(int j = 0 ; j < 2 ; j++)   //其中j<n,n即为要替换的第几个
      index = strBuf.toString().indexOf("BB",index + 2);
    strBuf.replace(index,index + 2,"12");
    System.out.println(strBuf);