【问题标题】:Java string: character replacing in sentenceJava字符串:句子中的字符替换
【发布时间】:2014-02-01 19:40:29
【问题描述】:

“这里是保险和保险研究所。” 在这句话中,如何用 JSS 替换 Institute 的前三个字符? 需要这样显示:“This is JSStitute of insurance and insu。”

【问题讨论】:

    标签: java string replace char


    【解决方案1】:

    使用字符串替换功能

     String sentence = "This is institute of insurance and insu.";
     sentence = sentence.replace("institute", "JSStitute");
    

    【讨论】:

      【解决方案2】:
      String s = "This is institute of insurance and insu.".replaceFirst("ins", "JSS");
      

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 2015-05-31
        • 1970-01-01
        • 2012-04-03
        • 2013-07-23
        相关资源
        最近更新 更多