6

i am wondering how i do a % sign within a NSString, i have tried \% and \\%

user393273
  • 1,430
  • 5
  • 25
  • 48
  • 3
    possible duplicate of [How to add percent sign to NSString](http://stackoverflow.com/questions/739682/how-to-add-percent-sign-to-nsstring) – Felix Kling Oct 11 '10 at 08:31

4 Answers4

14

Try %%.

Short question, short answer. :)

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
4

just put %% to use a % sign within objective c.

Gyani
  • 2,241
  • 1
  • 24
  • 38
4

There's no special escaping required for percent signs. Just write:

str = @"Rate of Return (in %)";

...unless you mean NSString stringWithFormat. But your question doesn't say so.

Codo
  • 75,595
  • 17
  • 168
  • 206
3

According to Apple's 'String Format Specifiers' page, simply use %%.

For example:

NSString * aString = @"50%%";

Reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

izakage
  • 43
  • 4