質問

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