Apart from @rmaddy's answer, mine case is different here.
Actually I used NSMutableAttributedString
in JSON parsing to send details on server.
At parsing time I got exception because NSMutableAttributedString
contains information about other attributes too, like color space
. Because of that it wont parse.
I tried many other ways but finally got solution to get string using below code:
// "amountString" is NSMutableAttributedString string object
NSMutableAttributedString *mutableString = (NSMutableAttributedString *)amountString;
amountValueString = [mutableString string];
amountValueString = [NSString stringWithFormat:@"%@", amountString];
NSRange fullRange = NSMakeRange(0, amountString.length);
NSAttributedString *attStr = [mutableString attributedSubstringFromRange:fullRange];
NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute:NSPlainTextDocumentType};
NSData *textData = [attStr dataFromRange:fullRange documentAttributes:documentAttributes error:NULL];
NSString *amountValueString = [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];