Get nth character of a string in Swift programming language

后端 未结 30 1970
一整个雨季
一整个雨季 2020-11-22 01:26

How can I get the nth character of a string? I tried bracket([]) accessor with no luck.

var string = \"Hello, world!\"

var firstChar = string[         


        
30条回答
  •  感情败类
    2020-11-22 01:45

    Update for swift 2.0 subString

    public extension String {
        public subscript (i: Int) -> String {
            return self.substringWithRange(self.startIndex..) -> String {
            get {
                return self.substringWithRange(self.startIndex.advancedBy(r.startIndex)..

提交回复
热议问题