gpt4 book ai didi

iphone - 如何将数组中的多个值转换为以逗号分隔的字符串

转载 作者:行者123 更新时间:2023-12-01 18:02:03 33 4
gpt4 key购买 nike

我试图使用componentSeparatedByString:@“,”将字符串插入具有多个值的数据库中。我正在获取“arrayp1net”中的所有值,但问题是如何制作一个包含以逗号(,)分隔的“arrayp1net”数组所有值的字符串?

if(p1h < 18)
{
for(int k=0;k<[arrayp1 count];k++)
{
if([[hcar1 objectAtIndex:1]intValue] >= [[ar33 objectAtIndex:k] intValue])
{
NSString *str = [NSString stringWithFormat:@"%d",[[[arrayp1 objectAtIndex:k] text] intValue] -1];
[arrayp1net addObject:str];
}
else
{
NSString *str = [NSString stringWithFormat:@"%d",[[[arrayp1 objectAtIndex:k] text]intValue]];
[arrayp1net addObject:str];
player1netscore = [NSString stringWithFormat:@"%@",arrayp1net];
}
}

是的,我需要相同的内容,但我必须在数据库中将其插入查询的一列中,以便在我要提取时按原样提取所有内容。
query=[NSString stringWithFormat:@"insert into normalscoring  
(gameid,coursename,p1,p2,p3,p4,p1s,p2s,p3s,p4s,gameDate,p1nets,p2nets,p3nets,p4nets)
values (\'%@\',\'%@\',\'%@||%@\',\'%@||%@\',\'%@||%@\',\'%@||%@\',
',,,,,,,,,,,,,,,,,||0||0||0||0',
',,,,,,,,,,,,,,,,,||0||0||0||0',
',,,,,,,,,,,,,,,,,||0||0||0||0',
',,,,,,,,,,,,,,,,,||0||0||0||0',
\'%@\',',,,,,,,,,,,,,,,,,',
',,,,,,,,,,,,,,,,,',',,,,,,,,,,,,,,,,,',',,,,,,,,,,,,,,,,,')",
txtgameid.text,txtcoursename.text,txtplayer1.text,player1handicap,
txtplayer2.text,player2handicap,txtplayer3.text,player3handicap,
txtplayer4.text,player4handicap,txtdate.text];

这是我在if语句后尝试做的但是得到异常的东西
player1netscore = [NSString stringWithFormat:@"%@",arrayp1net];
arn11=[player1netscore componentsSeparatedByString:@","];
player1netscore=[[arn11 objectAtIndex:0] objectForKey:@"p1nets"];
NSLog(@"player1netscore...%@",player1netscore);

最佳答案

使用 -[NSArray componentsJoinedByString:] :

NSString *stringp1net = [arrayp1net componentsJoinedByString:@","];

关于iphone - 如何将数组中的多个值转换为以逗号分隔的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8162825/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com