Android:从ResponseBy中将一个字符串分成两个字符串值

Android:从ResponseBy中将一个字符串分成两个字符串值,android,Android,使用此函数,我从服务器获得一个字符串作为响应: String responseBody = EntityUtils.toString(response.getEntity()); 我检索的字符串值大致如下所示: "http://url.com 765889" 我想把URL和数字分成两个字符串值,应该是: String 1="http://url.com" String 2="765889" 我怎样才能做到这一点呢?也许是这样 String 1 = responseBody.substri

使用此函数,我从服务器获得一个字符串作为响应:

String responseBody = EntityUtils.toString(response.getEntity());
我检索的字符串值大致如下所示:

"http://url.com 765889"
我想把URL和数字分成两个字符串值,应该是:

String 1="http://url.com" 
String 2="765889"
我怎样才能做到这一点呢?

也许是这样

String 1 = responseBody.substring(0,responseBody.indexOf(" ")-1);
String 2 = responseBody.substring(responseBody.indexOf(" ").responseBody.length()-1);
使用以下功能:

String[] parts = responseBody.split(" ");
Simples就是这样做的

    StringTokenizer t = new StringTokenizer("http://url.com 765889"," ");
    Log.d("first", t.nextToken());
    Log.d("second", t.nextToken());
请尝试将“”作为分隔符的StringTokenzier请注意,这被认为是遗留的-应使用新代码。