相关疑难解决方法(0)

NSLocale和国家/地区名称

我使用此代码来获取iPhone所属的国家/地区:

NSLocale *locale = [NSLocale currentLocale];
NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
NSString *country = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
Run Code Online (Sandbox Code Playgroud)

我希望国家名称始终使用英语,但如果iPhone使用任何其他语言,则返回该语言的国家/地区名称...

iphone objective-c

40
推荐指数
2
解决办法
5万
查看次数

Swift在字符串中的2个字符串之间获取字符串

我从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)

string substring ios swift

34
推荐指数
9
解决办法
2万
查看次数

从iOS中的字符串中删除括号

我试图删除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)

需要一些指导......

objective-c ios

2
推荐指数
1
解决办法
4811
查看次数

标签 统计

ios ×2

objective-c ×2

iphone ×1

string ×1

substring ×1

swift ×1