Search code examples
swiftnsnumberformatter

remove NSNumberFormatter hyphen


i am using this code,

var number:NSNumber = NSNumber .numberWithInteger(mylabel.integerValue)
        var numberFormatter : NSNumberFormatter = NSNumberFormatter()
        numberFormatter.numberStyle = NSNumberFormatterStyle.SpellOutStyle
        numberFormatter.formatterBehavior = NSNumberFormatterBehavior.BehaviorDefault
        self.displyingLabel.text = numberFormatter .stringFromNumber(number)

if enter this number - 8555

the output shows " eight thousand five hundred fifty-five " I want to remove the hyphen in the output, Is there any way in which we can remove the hyphen and replace it with an "and". Thanks in advance.


Solution

  • NSString *str = numberFormatter.stringFromNumber(number);
    str = [str stringByReplacingOccurrencesOfString:@"-" withString: @" and "]; 
    

    can be also a one-liner, if you wish.