swift 批量 取出中间文本

    func stringmid_pl (wholestring:String,front:String,behind:String,inout return_string:String,getheroid:Bool)

        

    {

        //数组参数inout

       

        // var whole_tmp:String = wholestring

        

 

        

        if wholestring.isEmpty

        {

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

            

        }else  {

            

            var whole:NSString=wholestring

            var whole_tmp = whole

           

            

            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_string = return_string + (whole as String) + ","

                    

//                  whole_tmp = whole_tmp.stringByReplacingOccurrencesOfString(front, withString: "", options: NSStringCompareOptions.LiteralSearch, range: frontindex)

//                    

//                  whole_tmp = whole_tmp.stringByReplacingOccurrencesOfString(behind, withString: "", options: NSStringCompareOptions.LiteralSearch, range: whole_tmp.rangeOfString(behind))

                    

                    

                  whole_tmp = whole_tmp.stringByReplacingOccurrencesOfString(front + (whole as String) + behind, withString: "")

                 if getheroid == true

                 {

                    whole_tmp = whole_tmp.stringByReplacingOccurrencesOfString(front + (whole as String), withString: "")

                    }

                

                    

                stringmid_pl(whole_tmp as String, front: front, behind: behind, return_string: &return_string,getheroid:getheroid)

                    

                    

                   // return(whole as String)

                    

                } else {

                   // return(return_string)

                } //没有找到behindwholestring

                

                

            } else  {

                //return(return_string)

            }  // 没有找到front wholestring

        

        

        

        

    

    }

    

    

    

 

 

    

}

原文地址:https://www.cnblogs.com/youyaoqi/p/5486651.html