本文介绍了如何做一个不区分大小写字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜的朋友我创建一个应用程序。

我想找到在一个特定的词的ArrayList ,我不得不更换

它与另一个词。我用下面的code。它的工作原理区分大小写,

但我希望得到它的工作不区分大小写。

Hi friends I'm creating an app.
I want to find a particular word in an ArrayList and I have to replace
it with another word. I used the code below. It works case sensitive,
but I'd like to get it working case insensitive.

   FillintheBlank.class: 

          public class FillintheBlank extends Activity {
        static ArrayList<String> multiword=new ArrayList<String>();

 static ArrayList<String> multimeaning=new ArrayList<String>();


public void setNoTitle() {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
} 
 float screenHeight,screenWidth,screendensity;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setNoTitle();
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     DisplayMetrics displaymetrics = new DisplayMetrics();
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
     screenHeight = displaymetrics.heightPixels;
     screenWidth = displaymetrics.widthPixels;
     screendensity = displaymetrics.densityDpi;
    setContentView(R.layout.fillinblanknew);

             multiword.add("radha");
             multiword.add("RAdHA");
              multiword.add("latha");
                multiword.add("mammu");

              s.o.p(""+multiword);
            // output:radha,RADHA,latha,mamu

          multimeaning.add(multiword.getString().replace(radha,"sai"));
        s.o.p(""+multimeaning);
     // output: sai,RADHA,latha,mamu

 }
  } 

例如:我需要'西'来代替'拉达'不管在'拉达'的字母大小写是

For example: I need to replace 'radha' with 'sai' no matter what the case of the letters in 'radha' are.

推荐答案

可以使用正前pression。
只需添加(我)之前,您的字符串忽略大小写。

Could use a regular expression. Just add (?i) before your string to ignore case.

因此​​,例如:

multiword.getString()的replaceAll(?(我)茹,西);

这篇关于如何做一个不区分大小写字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 13:40