Objective-C - How To Remove Characters From a String?

Posted by iAm on Stack Overflow See other posts from Stack Overflow or by iAm
Published on 2010-02-18T15:50:33Z Indexed on 2010/04/23 6:43 UTC
Read the original article Hit count: 325

I have a UILable that has a formatted String (formatted for currency), so there is a dollar sign, $21.34.

In the core data entity the attribute is of a type double, I am using an NSDecimalNumber to save to the database.

    self.purchase.name = self.nameTextField.text;
    NSString *string = self.amountLabel.text
    NSDecimalNumber *newAmount = [[NSDecimalNumber alloc] initWithString:string];
    NSLog(@"%@", string); // THIS RETURNS NaN, because of dollar sign i think

    NSManagedObjectContext *context = self.purchase.managedObjectContext;

    NSError *error = nil;
    if (![context save:&error]) 
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

Anyway, I need this to not be NaN, so my thinking is to remove the dollar sign, but i do not know how to do that, or perhaps there is a better way to accomplish my goal.

© Stack Overflow or respective owner

Related posts about nsdecimalnumber

Related posts about objective-c