![swift 取出中间文本 swift 取出中间文本](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
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("")} //没有找到behind在wholestring
} else {return("")} // 没有找到front 在wholestring
}
}