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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top