2013-02-24 63 views
-4

对不起,我真的跛脚的问题,只是想通了,我不熟悉的字符串操作O_0我已经是一个字符串的Java搜索

http://oauth.vk.com/blank.html#access_token= 533bacf01e11f55b536a565b57531ad114461ae8736d6506a3&expires_in=86400&user_id=8492 

什么,我需要的是3串:

access token="533bacf01e11f55b536a565b57531ad114461ae8736d6506a3" 
expiration="86400" 
    user_id="8492" 

如何将给定的字符串分成我需要的3个字符串?感谢

回答

1

希望这有助于:

String str = "http://oauth.vk.com/blank.html#access_toke..."

str = str.substring(str.indexOf("#") + 1);

str.split("&");

干杯

+0

感谢,这工作。 – Droidman 2013-02-24 18:44:02

1

尝试这个片段中,使用正则表达式:

String url = "http://oauth.vk.com/blank.html#access_token=533bacf01e11f55b536a565b57531ad114461ae8736d6506a3&expires_in=86400&user_id=8492"; 

Pattern pattern = Pattern.compile(".+access_token=(.+)&expires_in=(.+)&user_id=(.+)"); 
Matcher matcher = pattern.matcher(url); 

if (matcher.matches()) { 
    System.out.println("access_token=" + matcher.group(0)); 
    System.out.println("expires_in=" + matcher.group(1)); 
    System.out.println("user_id=" + matcher.group(2)); 
} 

的三场中终止(分别)组0,1和匹配器对象的2。