uml
uml

Reputation: 1189

Inserting a string into another string

I am working on iPhone app. I have the SQL query:

 NSString *myRed = [NSString stringWithFormat: @"%1.4f", slideR.value];

 [self insertData:@"INSERT INTO colour VALUES("+myRed+")"];

It produces syntax error. How to insert a string into string. That approach in Java would have worked. Best regards

Upvotes: 1

Views: 129

Answers (2)

AgnosticDev
AgnosticDev

Reputation: 1853

You could try writing your query and your string appended together before hand.

             NSString *str = @"Your values";
             NSString *query = [NSString stringWithFormat:@"INSERT INTO color VALUES(%@)", str];
             [self insertData:query];

Upvotes: 1

P.J
P.J

Reputation: 6587

Try this :

NSString *myRed = [NSString stringWithFormat: @"%1.4f", slideR.value];

[self insertData:[NSString stringWithFormat:@"INSERT INTO colour VALUES(\"%@\")",myRed]];

If you don't want " then :-

[self insertData:[NSString stringWithFormat:@"INSERT INTO colour VALUES(%@)",myRed]];

Hope it helps you.

Upvotes: 1

Related Questions