比如有一个字符创为
"I am a Chinese people."
怎样修改为
"I am a Beijing people."

解决方案 »

  1.   

    "I am a Chinese people.".repalceAll("Chinese","Beijing");
      

  2.   

    str=str.replaceAll("Chinese", "Beijing");
      

  3.   


    String str = "I am a Chinese people." ;
    String newStr="";
    String strArr[] = str.spit(" ");
    for(int i=0;i<strArr.length;i++){
      if(str.equals("Chinese")){
        strArr[i]="Beijing";
      }
    }
    for(int i=0;i<strArr.length;i++){
      newStr+=strArr[i]+" ";
    }
      

  4.   


    return "I am a Chinese people.".replace("Chinese", "Beijing");
      

  5.   


    public class Test { 

    public static void main(String args[]) {

    String s = "I am a Chinese people";
    s = s.replaceAll("Chinese","Beijing");
    System.out.println(s);
        }
    }
      

  6.   

    String str="I am a Chinese people." ;
    String newStr=str.replaceAll("Chinese", "Beijing")
      

  7.   

    String str = "I am a Chinese people.";
    String replace = str.replaceAll("Chinese", "Beijing");
    System.out.print(replace);
      

  8.   


    这个正解,不要乱用 replaceAll,这个方法要用正则表达式做匹配替换,效率远没有直接了当的 replace 高(效率低但功能强大),简单的字符串替换用 replace 比 replaceAll 即快又不容易出错。
      

  9.   

    完整代码:public class ChangeString { /**
     * @param args
     */
    public static void main(String[] args) {
    System.out.println(ChangeString.method1()); }

    public static String method1(){
     return "I am a Chinese people".replace("Chinese", "Beijing"); }}
      

  10.   

    楼上说的方法都行。要注意的是String类里的replaceAll方法参数的字符串用的是正则表达式,不是普通字符串。只不过“Chinese”的正则表达式就是“Chinese”。
      

  11.   

    可以用aparch里的StringUtile包里replace方法。
    不过这句话好像这样写好点,
    "I am a Chinese"
    "I am a BeiJingnese"
      

  12.   

    同感 beijing != chinese