1. 字符串与数组互转
OC
NSMutableString * str=[[NSMutableString alloc]initWithFormat:@"1,1,1,1,1,1"];
//字符串转变为数组
NSMutableArray * array=[NSMutableArray arrayWithArray:[str componentsSeparatedByString:@","]];
//把数组转换成字符串
NSString *ns=[array componentsJoinedByString:@","];
Swift
import UIKit
let str = "1,1,1,1,1"
//字符串转变为数组
let array = str.components(separatedBy: ",")
//把数组转换为字符串
let ns = array.joined(separator: ",")
网友评论