我使用此代码来获取iPhone所属的国家/地区:
NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
Run Code Online (Sandbox Code Playgroud)
我希望国家名称始终使用英语,但如果iPhone使用任何其他语言,则返回该语言的国家/地区名称...
我从html解析中得到一个字符串;
string = "javascript:getInfo(1,'Info/99/something', 'City Hall',1, 99);"
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的
var startIndex = text.rangeOfString("'")
var endIndex = text.rangeOfString("',")
var range2 = startIndex2...endIndex
substr= string.substringWithRange(range)
Run Code Online (Sandbox Code Playgroud)
我不确定我的第二个分裂字符串应该是"'"还是"","
我想要我的结果
substr = "Info/99/something"
Run Code Online (Sandbox Code Playgroud) 我试图删除iOS中我的字符串中的所有括号.看到这个stackoverflow帖子:如何删除空格,括号和"来自nsarray
答案:
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
Run Code Online (Sandbox Code Playgroud)
但这只是删除一个括号(来自mystring.如何删除所有这些?
我的代码看起来像这样:
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"( )"];
attributedLabel.text = [attributedLabel.text stringByTrimmingCharactersInSet:charsToTrim];
NSLog(@"%@",attributedLabel.text);
Run Code Online (Sandbox Code Playgroud)
需要一些指导......