Pergunta

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

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top