Nari
Nari

Reputation: 213

How to remove the last character from an NSMutableString

Iam adding some text content to nsmutablestring in the form of dictionary format and again that every dictionary is split by ","(commos). But when getting this total string its displays (,) to string of ending. So how to remove that ","(commos) in that mutable string.

Please guide me if any one knows

Thanking in advance

Upvotes: 3

Views: 5429

Answers (3)

Oliver
Oliver

Reputation: 23510

Doing that way, you keep the mutable property of your string:

[mutableString setString:[mutableString substringToIndex:[mutableString length]-1]];

Upvotes: 7

Luke Pullman
Luke Pullman

Reputation: 98

To remove the last character of a string you can write:

string = [string substringToIndex:[string length] - 1];

Upvotes: 3

girish
girish

Reputation: 900

This is how you need to remove character from NsmutableString....

NSRange range = NSMakeRange([concatedstring length]-1,1);
[concatedstring replaceCharactersInRange:range withString:@""];

Upvotes: 11

Related Questions