swift字符串

2019-02-27  本文已影响0人  水灵芳蕥

字符串插入:str.insert(" ", at: str.index(str.startIndex, offsetBy:3))

字符串替换:str.replacingOccurrences(of: " ", with: "")

截取字符串:

前3个:str.prefix(3) 

后3个:str.substring(from: 3)

打印字符串:NSLog("\(sub1)  \(sub2)  \(sub3)  \(sss)")

functextField(_textField:UITextField, shouldChangeCharactersIn range:NSRange, replacementString string:String) ->Bool{

        ifstring.isNonEmpty(),varstr = textField.text{

            str += string

             str = str.replacingOccurrences(of:" ", with:"")

            ifstr.count>3{

                str.insert(" ", at: str.index(str.startIndex, offsetBy:3))

            }

            ifstr.count>8{

                str.insert(" ", at: str.index(str.startIndex, offsetBy:8))

            }

            textField.text= str

            returnfalse

        }

        return true

    }

上一篇 下一篇

猜你喜欢

热点阅读