【发布时间】:2018-08-12 22:49:48
【问题描述】:
我有两种情况需要将字符串转换为不同的格式。
例如:
case 1:
string inputs: abc, xyz, mno, & llr // All Strings from a dictionary
output: ["abc","xyz", "mno", "llr"] //I need to get the String array like this.
但是当我使用这段代码时:
var stringBuilder:[String] = [];
for i in 0..<4 {
stringBuilder.append("abc"); //Appends all four Strings from a Dictionary
}
print(stringBuilder); //Output is 0: abc, 1:xyz like that, how to get desired format of that array like ["abc", "xyz"];
实际用法:
let arr = Array(stringReturn.values);
//print(arr) // Great, it prints ["abc","xyz"];
let context = JSContext()
context?.evaluateScript(stringBuilder)
let testFunction = context?.objectForKeyedSubscript("KK")
let result = testFunction?.call(withArguments:arr); // Here when I debugger enabled array is passed to call() like 0:"abc" 1:"xyz". where as it should be passed as above print.
其次,如何在 swift 中替换转义字符:我在 replaceOccurances(of:"\\'" with:"'"); 中使用了“\”,但它没有改变。为什么以及如何逃避该序列。
case 2:
string input: \'abc\'
output: 'abc'
【问题讨论】:
-
您可以编辑您的问题以包含您的字典的定义吗?
-
var stringReturn:Dictionary = Dictionary
();是定义。 -
甚至 [String:Any] 也打印相同的 na
标签: arrays swift swift3 swift-string