我是 iphone 开发的新手,正在开发一个演示应用程序,因为我得到了一个像“abc%26def”这样的字符串,我想解码这种类型的文本以进行实际测试,我知道它非常基本的问题,但仍然我无法从链接中找到任何解决方案,所以任何伙伴都可以帮助我吗?
我的代码如下
if(i%3==0)
{
[dataDictionary setValue:[dataDictionary valueForKey:TRIPPER__KEY] forKey:CONTENT_KEY];
[dataDictionary setValue:CELL_TEXTFIELD_TRIPPER_COUNT forKey:@"cellIdentifier"];
}
else if(i%3==1)
{
//*name = [(NSString *)self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
NSString *name = [[dataDictionary valueForKey:NAME_KEY] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dataDictionary setValue:name forKey:CONTENT_KEY];
[dataDictionary setValue:CELL_TEXTFIELD_TRIPPER_NAME forKey:@"cellIdentifier"];
[dataDictionary setValue:@"Triper Name" forKey:@"placeHolder"];
}
最佳答案
我认为这肯定有效
NSString *str = @"abc%26def"; //put any string that you want
NSCharacterSet *setToKeep = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
NSCharacterSet *setToRemove = [setToKeep invertedSet]; //inverted set will have all other remaining symbol, char etc
NSString *newString =[[str componentsSeparatedByCharactersInSet:setToRemove]componentsJoinedByString:@""]; //this is the decoded string
NSLog(@"%@",newString);
如果您还需要更多内容,请发表评论,我会修改答案。
关于ios - 如何解码 objective-c 中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201564/