【问题标题】:Filter a String in android [duplicate]在android中过滤字符串[重复]
【发布时间】:2015-12-01 02:23:01
【问题描述】:
String test = "{helloworld=Text to be filtered}";

我需要从上面的字符串中获取“要过滤的文本”。 请帮忙。提前致谢。

【问题讨论】:

  • 发布你的尝试..
  • 对不起,我是初学者。我不知道。请帮忙。
  • 我感到很困惑。请帮忙。
  • JSON解析后,我列出了ListView中的项目。在获取项目值时,我得到这种类型的字符串:“{helloworld=要过滤的文本}”。所以我需要得到“要过滤的文本”。

标签: android string


【解决方案1】:

在这种情况下你可以使用 String.split() 方法。

String test = "{helloworld=Text to be filtered}";
String testAfterSplit[] = test.split("=");

testAfterSplit[0] 将持有值“{helloworld”和 testAfterSplit[1] 将持有值“要过滤的文本}

你可以阅读更多关于拆分here

【讨论】:

  • 我自己得到了答案! String test = "{helloworld=要过滤的文本}";字符串 test2 = test.replace("{helloworld=","");字符串 test3 = test2.replace("}","");现在我可以使用 test3 字符串了:D 这就是我自己发现的。
【解决方案2】:

您可以使用 indexOf 方法。它会重新运行您想要的角色位置。在这种情况下:

int pos = text.IndexOf("=");
String filter = text.substring(pos, text.length());

它返回一个从=位置到结尾的字符串。

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2021-10-03
    • 2020-11-13
    • 2021-12-09
    • 2019-11-02
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 2019-09-30
    相关资源
    最近更新 更多