Converting to Char/String from Ascii Int in Swift

后端 未结 3 1346
萌比男神i
萌比男神i 2021-01-17 17:22

I\'m trying to convert the integer representation of an ascii character back into a string.

string += (char) int;

In other languages like J

3条回答
  •  时光说笑
    2021-01-17 17:45

    If you want only String characters from A... you can use this func:

    func characterFromInt(index : Int) -> String {
            let startingValue = Int(("A" as UnicodeScalar).value)
            var characterString = ""
            characterString.append(Character(UnicodeScalar(startingValue + index)))
            return characterString
        }
    

提交回复
热议问题