-1

I have a NSMutableString variable that i append from aString, like this:

NSString  *aString = [NSString stringWithFormat:@"{\"MyCode\":%@,\"TotalAmount\":%@,\"PaymentType\":\"%@\",\"BankName\":\"%@\",\"BankAccountNo\":\"%@\",\"Amount\":\"%@\",\"FileName\":\"%@\"}",aCode,total,type,labelBank.txt,labelAcc.txt,aTrasfer,imageName];

[teststring appendString:asstring2];
[teststring appendString:@","];

in this code i sucess to append the string in order they append. But know i want to append a new string in the first position, just like in array object at index 0.Can NSMutableString do this?

Hope my question is clear..thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2373192
  • 31
  • 1
  • 5
  • 2
    Please look at the reference docs before asking a question like this. One minute looking at the NSMutableSting docs would have showed the proper methods for this. – rmaddy Aug 01 '13 at 03:19
  • @rmaddy I am surprised how many people are like "hey wouldn't it be cool if X method existed" only to find them in the documentation. Aren't you supposed to look there first? – Justin Meiners Aug 01 '13 at 03:21

1 Answers1

1

You said it, with an index. Same way as you do with an array.

- (void)insertString:(NSString *)aString atIndex:(NSUInteger)anIndex

Your code:

[testString appendString:aString];
[testString insertString:@"," atIndex:0]; /* prepend the comma

Check out the Documentation

Justin Meiners
  • 10,754
  • 6
  • 50
  • 92