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

来源:转载

//替换

var ReplaceString = "http://www.aimonkey。cn";

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

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

 

//过滤(单个字符)

 

var DeleteString = "http://www.aimonkey。cn";

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

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

 

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

var SpaceString = " http://www.aimonkey。cn ";

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

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

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

var SplitStringItem = "Angel";

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

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: