我需要帮助,我有以下代码:
NSString* string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray* params= [string componentsSeparatedByString:@"\\"];
lugar = params[0];
texto1 = params[1];
texto2 = params[2];
texto3 = params[3];
NSString *query;
query =[NSString stringWithFormat:@"INSERT INTO CONTENIDO VALUES(null,'%@','%@','%@','%@')", lugar,texto1,texto2,texto3];
// Execute the query.
[self.dbManager executeQuery:query];
// If the query was successfully executed then pop the view controller.
if (self.dbManager.affectedRows != 0) {
NSLog(@"Query was executed successfully. Affected rows = %d", self.dbManager.affectedRows);
}
并收到如下字符串文字:34 \ field1 \ DFR23 \ good \ 35 \ field2 \ DFR24 \ good \ 36 \ field3 \ DFR25 \ bad
我的代码用\
分隔前四个空格,但是我需要插入一个所有空格都在数组中的循环,请帮助我吗?
答案 0 :(得分:0)
您可以使用stringByAppendingString方法将一个字符串连接到另一个字符串。
做这样的事情:
long numberOfSpaces = [params count];
NSString queryString = @"@"INSERT INTO CONTENIDO VALUES(null";
for (int i = 0; i < numberOfSpaces; i++) {
NSString *nextParam = [NSString stringWithFormat:@",//'%@",params[i]];
queryString = [queryString stringByAppendingString:nextParam;
}