swift--字符串替换/过滤/切割

//替换

var ReplaceString = "http://www.aimonkeycn";

var FilterReplace = ReplaceString.stringByReplacingOccurrencesOfString("", withString: ".", options: NSStringCompareOptions.LiteralSearch, range: nil);

//输出 "http://www.aimonkey.cn"

 

//过滤(单个字符)

 

var DeleteString = "http://www.aimonkeycn";

var FilterDelete = DeleteString.stringByReplacingOccurrencesOfString("", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil);

//输出 "http://www.aimonkeycn"

 

//过滤开头和结尾的空白

var SpaceString = " http://www.aimonkeycn ";

var AllString = SpaceString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet());

//输出 "http://www.aimonkeycn"

//切割(返回一个数组)

var SplitStringItem = "Angel";

var ResultString = SplitStringItem.componentsSeparatedByString("n");

//输出 ["A", "gel"]

你可能感兴趣的:(swift--字符串替换/过滤/切割)