【问题标题】:How to split string in android如何在android中拆分字符串
【发布时间】:2018-08-20 09:07:48
【问题描述】:

假设我有一个字符串,下面

String myText="I'm a android developer and i'm developing an android app";

所以我想用(" ' "), 分割上面的字符串,并想把它放在一个 textView 上,这样怎么可能。我用过这段代码

split(Pattern.quote("'"));

所以我的完整代码是:

 textUser.setText(User);
        String[] newDesc=Description1.split(Pattern.quote("'"));
        for(String w:newDesc){
            textDesc.setText(w);
        }

但这不起作用。请解决我的问题

【问题讨论】:

  • 只需您以String[] newDesc=Description1.split("'"); 的身份执行此操作

标签: android string split


【解决方案1】:

我相信Pattern.quote() 包装了您的正则表达式,以便它仅在匹配字符串包含在引号内时才有效。

换句话说,我不相信在这种情况下它会起作用。

一个简单的String[] newDesc=Description1.split("'"); 应该可以工作。

【讨论】:

    【解决方案2】:

    请用这个

    String[] newDesc=Description1.split("'");
    

    【讨论】:

      【解决方案3】:

      使用下面的代码来理解你需要的分割字符串:

      例如:String myText = "I'm a android developer and i'm developing an android app";

      String[] strParts = myText.split("'");
      

      然后

      String strFirstString = strParts[0]; // I
      String strSecondString = strParts[1]; // m a android developer and i
      String strThirdString = strParts[2]; // m developing an android 
      

      现在在你的 textView 中显示你想要的任何字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-13
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-26
        相关资源
        最近更新 更多