【问题标题】:Split string in android在android中拆分字符串
【发布时间】:2015-10-09 04:15:04
【问题描述】:

我正在尝试拆分字符串。例如“城堡”

String text = "Castle";
            String[] word = text.split("c");
            Log.d(Constants.RESULT, "1:" + word[word.length-1]);

我希望结果是 (1:astle)。相反,我得到 (1:Castle) 我希望你们能帮帮我。谢谢!

【问题讨论】:

  • 因为 "c" != "C"。
  • 如果你想要不区分大小写的拆分,你可以参考这个SO post
  • 我只是以“城堡”为例。它不必总是那个词或大写字母
  • 不是说不区分大小写吗?

标签: android string


【解决方案1】:

使用String[] word = text.split("C");

【讨论】:

    【解决方案2】:

    简单的一点是字母'c'和'C'不同,你用的是'c',最好用'C',

    试试这个

    String text = "Castle";
                String[] word = text.split("C");
                Log.d(Constants.RESULT, "1:" + word[word.length-1]);
    

    【讨论】:

      【解决方案3】:

      使用这个:

      String text = "Castle";
      String[] word = text.split("C");
      Log.d(Constants.RESULT, "1:" + word[1]);
      

      你从中得到了“aastle”

      【讨论】:

        【解决方案4】:

        使用

            String text = "Castle"; 
            String sub =text.substring(1,text.length); 
        
            Log.d( "Answer", "1:" + sub);
        

        【讨论】:

          猜你喜欢
          • 2011-04-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-08
          • 1970-01-01
          • 2012-08-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多