문제

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