这里是新手程序员,不明白为什么这样做......
let a1 = "This is some text"
let x : Int = 1
var stringValue = "a\(x)"
print(stringValue)
我希望它打印“这是一些文本”
,但它只打印a1
。
最佳答案
与其将“This is some text”存储在 a1 字符串中,不如将其保存在字典中,以便您可以创建 key (x1、x2 等)来访问它:
let stringDictionary = ["a1": "This is some text", "a2": "This is more text"]
然后您可以使用以下方法将其拉出:
let x : Int = 1
let stringKey = "a\(x)"
let stringValue = stringDictionary[stringKey]
print(stringValue)
关于ios - 使用 Int,结合 String 打印现有的 String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36195967/