美文网首页
字符串 为空判断

字符串 为空判断

作者: devleoper_rui | 来源:发表于2018-09-26 09:37 被阅读7次

    Swift 字符串 为空判断 并返回字符串

    func emptyString(_ str :AnyObject)-> String
    {
    var string = str

        var isNO:Bool!
        isNO = false
        if ((string as AnyObject).isEqual(String.init()))
        {
            isNO = true
        }
        else if ((string as AnyObject).isEqual(NSNull.init()))
        {
            
            isNO = true
        }
            
        else if (string as! String == "\("")")
        {
            isNO = true
        }
        else if (string as! String == "\("null")")
        {
            isNO = true
        }
        else if (string as! String == "\("(null)")")
        {
            isNO = true
        }
        else if (string as! String == "\("<null>")")
        {
            isNO = true
        }
        else if (string.isEmpty)
        {
            isNO = true
        }
            
        else if (string.length == 0)
        {
            isNO = true
        }
        else
        {
            isNO = false
        }
        
        if (isNO == true) {
            string = "" as AnyObject as AnyObject
        }
        
        return string as! String
    }

    相关文章

      网友评论

          本文标题:字符串 为空判断

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