[iOS]拾遗补阙
程序员文章站
2023-11-23 10:52:34
一、AFNetworking POST字符串 修改位置AFURLRequestSerialization 修改前 修改后 二、查找一个字符串中的多个相同子字符串 ......
一、afnetworking post字符串
修改位置afurlrequestserialization
修改前
nsstring * afquerystringfromparameters(nsdictionary *parameters) { nsmutablearray *mutablepairs = [nsmutablearray array]; for (afquerystringpair *pair in afquerystringpairsfromdictionary(parameters)) { [mutablepairs addobject:[pair urlencodedstringvalue]]; } return [mutablepairs componentsjoinedbystring:@"&"]; }
修改后
nsstring * afquerystringfromparameters(nsdictionary *parameters) { if ([parameters iskindofclass:[nsstring class]]) return (nsstring *)parameters; nsmutablearray *mutablepairs = [nsmutablearray array]; for (afquerystringpair *pair in afquerystringpairsfromdictionary(parameters)) { [mutablepairs addobject:[pair urlencodedstringvalue]]; } return [mutablepairs componentsjoinedbystring:@"&"]; }
二、查找一个字符串中的多个相同子字符串
nsstring *str = @"14 28 62 24 3 46 99 73 10 51 0 95 34 58 50 33 56 23 97 82 83 8 94 1 17 7 19 96 9 54"; nsstring *searchstring = @"1"; nsrange searchrange = nsmakerange(0, [str length]); nsrange range; while ((range = [str rangeofstring:searchstring options:0 range:searchrange]).location != nsnotfound) { nslog(@"%@",nsstringfromrange(range)); searchrange = nsmakerange(nsmaxrange(range), [str length] - nsmaxrange(range)); }
上一篇: 互联网已进入免费时代