本文介绍了iPhone解析GET参数的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从解析xml网站获得的字符串。

I have an string which is got from parsing an xml site.

http://www.arijasoft.com/givemesomthing.php?a=3434&b=435edsf&c=500

我想要有一个NSString函数,可以解析c的值。
是否有默认功能或我必须手动编写。

I want to have an NSString function that will be able to parse the value of c.Is there a default function or do i have to write it manually.

推荐答案

您可以通过RegExKit使用正则表达式精简版:

You could use Regular expression via RegExKit Lite:http://regexkit.sourceforge.net/RegexKitLite/

或者你可以将字符串分成组件(不太好):

Or you could separate the string into components (which is less nice):

NSString *url=@"http://www.arijasoft.com/givemesomthing.php?a=3434&b=435edsf&c=500";
NSArray *comp1 = [url componentsSeparatedByString:@"?"];
NSString *query = [comp1 lastObject];
NSArray *queryElements = [query componentsSeparatedByString:@"&"];
for (NSString *element in queryElements) {
    NSArray *keyVal = [element componentsSeparatedByString:@"="];
    if (keyVal.count > 0) {
       NSString *variableKey = [keyVal objectAtIndex:0];
       NSString *value = (keyVal.count == 2) ? [keyVal lastObject] : nil;
    }
}

这篇关于iPhone解析GET参数的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 15:35