Search code examples
objective-cnsstring

How to insert Non-breaking space to NSString or NSMutableAttributedString


How to insert Non-breaking space (like " " in html) to NSString or NSMutableAttributedString ?


Solution

  • As Xcode treats all source code files as UTF-8 encoded text files, it should be possible to directly paste the non-breaking space into your source code:

    NSString *text = @"100 feet long";  // non-breaking space between "100" and "feet"
    

    To be on the safe side and make it more obvious, you can insert the Unicode value U+00A0 into the string:

    NSString *text = @"100\u00a0feet long";