NSStrings joined with character in middle

I'm trying to create a single 'query' NSString object that basically looks like this:


ive got strings that look like this:


my question is this: is there an easy way to combine these 3 components by adding a ? character between them considering the number of strings is variable? i.e., a simple string with format is too inflexible for my purposes.


Well, if you have a variable number of strings to concatenate, you can just make them an array and join them by the @"&" string:

NSArray *components = [NSArray arrayWithObjects:query1, query2, query3, nil];
NSString *result = [components componentsJoinedByString:@"&"];

You can even make this into a variadic macro:

#define BUILD_QUERY(...) [[NSArray arrayWithObjects:__VA_ARGS__ , nil]

Need Your Help

iterating string in C, word by word

c string

I just started learning C. What I am trying to right now is that I have two strings in which each word is separated by white spaces and I have to return the number of matching words in both strings...

Rotate a 3D object on 3 axis in JavaFX properly

java javafx 3d quaternions javafx-3d

So the method that I've used so far to rotate objects in JavaFX was that I layered it in 3 groups, each of them with a Rotate attached and locked to a single axis like so: