首页 > 编程语言 > 详细

swift 取出中间文本

时间:2016-05-13 11:57:57      阅读:143      评论:0      收藏:0      [点我收藏+]

    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

            

           

        }

        

 

    }

swift 取出中间文本

原文:http://www.cnblogs.com/youyaoqi/p/5486647.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!