0

I'm looking for a simple way to create strings with different names in a loop. something like this,

nsstring *str1;
nsstring *str2;
nsstring *str3;

just with a

for loop 

to create about 100 of them.

MendyK
  • 1,643
  • 1
  • 17
  • 30
  • You cannot -- and should not -- do this. If you have a bunch of variables with numbers at the end of their names, you actually should have an array. See also [Create multiple variables based on an int count](http://stackoverflow.com/q/2231783), [Syntax help: variable as object name](http://stackoverflow.com/q/7940809), and [Is it possible to reference a variable with a string and an int?](http://stackoverflow.com/q/6049175) – jscs Sep 30 '14 at 18:41

1 Answers1

0

Something like this:

NSMutableArray* array = [NSMutableArray array];
for(int i=1; i<=100; i++){
    [array addObject:[NSString stringWithFormat:@"string%d", i]];
}

Array now should have 100 strings named like string1, string2, string3...and so on.

puru020
  • 808
  • 7
  • 20