1

i was trying to insert a string into database having multiple value using componentsSeparatedByString:@",". I am getting all the values in "arrayp1net" but problem is how to make a string that contains all the values of array "arrayp1net" separated by comma (,)?

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];
        }
    }

yes i need the same but i have to insert in database in one row of a column with query, so that when i am going to fetch, i fetch all as it is.

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];

here is what i am trying to do after if statement but getting exception

player1netscore = [NSString stringWithFormat:@"%@",arrayp1net];
arn11=[player1netscore componentsSeparatedByString:@","];
player1netscore=[[arn11 objectAtIndex:0] objectForKey:@"p1nets"];
NSLog(@"player1netscore...%@",player1netscore);

2 Answers 2

5

Use -[NSArray componentsJoinedByString:]:

NSString *stringp1net = [arrayp1net componentsJoinedByString:@","];
Sign up to request clarification or add additional context in comments.

2 Comments

do you know how to do it in android.? if not known then can you refer to any android developer so that i can ask about it.
I know how to search stackoverflow... stackoverflow.com/questions/1978933/…
0

I am not really clear about what you want.....but whatever I got from your question is you want a string which will contain the elements of arrayp1net array which will be comma seprated

     NSString *str = @"";    
   for(int i = 0; i< [arrayp1net count]; i++){

          str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,",[arrayp1net objectAtIndex:i]]];

      }

For this your arrayp1net should be NSMutable array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.