swift 取出中间文本

    func  stringmid (wholestring:String,front:String,behind:String)->String

    {

 

        

        

        if wholestring.isEmpty

        {

           return("") //wholestring 不能为nil

            

        }else  {

            var whole:NSString=wholestring

            

            

            let frontindex = whole.rangeOfString(front)

            if frontindex.length > 0

            {

                whole = whole.substringFromIndex(frontindex.location + frontindex.length)

                let behindindex = whole.rangeOfString(behind)

                if behindindex.length > 0

                {

                    whole = whole.substringToIndex(behindindex.location)

                

                    return(whole as String)

                    

                } else {return("")} //没有找到behindwholestring

               

                

            } else  {return("")}  // 没有找到front wholestring

            

           

        }

        

 

    }

posted @ 2016-05-12 17:42  、有妖气  阅读(153)  评论(0编辑  收藏  举报