【问题标题】:how to do substring of HttpResponse in android如何在android中做HttpResponse的子字符串
【发布时间】:2016-02-01 08:43:20
【问题描述】:

我想做以下 HttpResponse 的子字符串。

true#696.887#Nirmal Patel

这是字符串,我只想要整个字符串中的Nirmal patel

【问题讨论】:

标签: java android string


【解决方案1】:

你可以这样做,

String yourString = yourResponse.substring(yourResponse.lastIndexOf('#') + 1);

【讨论】:

  • 可能是yourResponse.substring(yourResponse.indexOf('#') + 1,yourResponse.lastIndexOf('#') );
【解决方案2】:

首先使用lastIndexOf方法

int index = YOUR_RESPONSE.lastIndexOf("#");

比使用subString 方法

YOUR_RESPONSE.subString((index+1),YOUR_RESPONSE.length());

【讨论】:

    【解决方案3】:
    String substring= httpresponse.substring(httpresponse.lastIndexOf('#')+1,httpresponse.length());
    

    【讨论】:

    • 这个打印#Nirmal pate i don't want # and last character is missing
    • 您能解释一下如何解决这个问题吗?
    • @deepakjohn141 我知道参考资料,但请遵循 stackoverflow 的指导方针。您的解决方案应说明好处以及如何解决问题。
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2011-12-01
    • 2016-01-29
    相关资源
    最近更新 更多