我有一个字符串,我想插入到 ObjCNSURL.UrlWithString
函数中,但它必须没有任何引号。
不好的例子:
$.NSURL.URLWithString("http://192.168.1.1")
在 JavaScript 中,我知道我可以做一些类似StringFromCharCode(34,90,81,33)
的事情来避免引号,但是 Objective C 中的替代方案是什么?(不是斯威夫特(。
JS String.fromCharCode((
文档:
静态
String.fromCharCode()
方法返回从指定的 UTF-16 代码单元序列创建的字符串。
console.log(String.fromCharCode(189, 43, 190, 61));
// expected output: "½+¾="
Obj-C NSString
+ (instancetype)stringWithCharacters:(const unichar *)characters
length:(NSUInteger)length;
文档:
返回一个字符串,其中包含从给定的 UTF-16 代码单元 C 数组中获取的给定数量的字符。
例
unichar chars[] = {189, 43, 190, 61};
NSString *s = [NSString stringWithCharacters:chars
length:sizeof(chars) / sizeof(unichar)];
NSLog(@"%@", s);
// expected output: ½+¾=
你知道C的printf语法吗?然后使用类似字符的内容
[NSString stringWithFormat:@"%c%c%c%c", 34, 90, 81, 33];
或者重复地将一个字符串附加到(可变(字符串中,一次使用字符创建一个字符串。
NSString * s1 = [NSString stringWithFormat:@"%c", c];