美文网首页
swift字符串

swift字符串

作者: 水灵芳蕥 | 来源:发表于2019-02-27 17:03 被阅读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

    }

相关文章

网友评论

      本文标题:swift字符串

      本文链接:https://www.haomeiwen.com/subject/psifuqtx.html