Objective C String concatenation example

Well in any programming language this is considered one of important string manipulation functions and as simple as adding a plus sign between the two strings. Guess what its not that easy in Objective C, here is how to achieve string concatenation when using either NSString or NSMutableString classes.
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        NSString *sql_stmt = @"CREATE TABLE IF NOT EXISTS EMPLOYEES (";
        sql_stmt = [sql_stmt stringByAppendingString:@"id INTEGER PRIMARY KEY AUTOINCREMENT, "];
        sql_stmt = [sql_stmt stringByAppendingString:@"name TEXT, "];
        sql_stmt = [sql_stmt stringByAppendingString:@"department TEXT, "];
        sql_stmt = [sql_stmt stringByAppendingString:@"age TEXT)"];

        NSLog(@"%@",sql_stmt);
        
        
        NSMutableString *sql_stmt2 = [[NSMutableString alloc] initWithString:@"CREATE TABLE IF NOT EXISTS EMPLOYEES ("];
        [sql_stmt2 appendString:@"id INTEGER PRIMARY KEY AUTOINCREMENT, "];
        [sql_stmt2 appendString:@"name TEXT, "];
        [sql_stmt2 appendString:@"department TEXT, "];
        [sql_stmt2 appendString:@"age TEXT)"];
        
        NSLog(@"%@",sql_stmt2);
        
    }
    return 0;
}


5 comments :

  1. Sometimes a bit tired of this boring cheap fifa 14 coins life, her daughter is very naughty, let me do anything, she looked at the. Family life is not a single time when the romantic and warm, had a really left his cheap fifa 14 coins own, perhaps this is real life!

    ReplyDelete
  2. Thank you for your guidance so sweet Yepi.Com, Friv 9 all this time later in Friv 8, Friv 7, I have found it Friv 6, Friv 100 and loved the final result Friv 6000, Friv 7000. I appreciate time you spend sharing your skills on Friv 8000,Friv 9000, Yepi Games !

    ReplyDelete
  3. Thanks for the great post Friv.Com, Friv.Com! I quite enjoyed reading it Kizi 6000, Kizi 7000 you can be a great author. Kizi 8000, Kizi 9000 I will remember to bookmark your blog and definitely will come back later Kizi 360, Kizi.Com. I want to encourage continue your great job Yepi 300, Yepi 5, have a nice day Yepi 600, Yepi 9000!

    ReplyDelete