Questions tagged [nsstring]

NSString is the plain-text character-string class in Cocoa and Cocoa Touch. See also NSMutableString, NSData and NSMutableData (for objects that contain bytes rather than human-language characters), and NSAttributedString and NSMutableAttributedString (for rich-text strings).

NSString is the plain-text character-string class in Cocoa () and Cocoa Touch ().

An NSString is immutable, unless it's an NSMutableString (). NSMutableString is a subclass of NSString.

You will never work with a direct instance of NSString or NSMutableString. Both classes, like most of the other property-list classes, are members of a class cluster.

NSStrings contain human-language characters; you should not attempt to use an NSString to store bytes, including pixel data and XML or HTML markup. (“String” in Cocoa strictly refers to human text; it does not call a byte array a “string” like Python 2 and some other environments do.) To make or receive an object bytes, you should use NSData or NSMutableData (note that, for example, this is what NSXMLParser, WebFrame, and UIWebView take for the XML/HTML source of the document, and what NSURLConnection gives you as you download a resource).

An NSString is always plain text. For rich text, use NSAttributedString or its mutable subclass. Both have always been available on Mac OS X, and have been available on iOS since 3.2.

NSString is toll-free bridged with CFString, which means you can pass an NSString to CF functions expecting a CFString, and receive a CFString and treat it as an NSString. The same goes for the mutable subclass.

Docs:

7124 questions
2
votes
2 answers

Objective-C Reusing NSString Memory Leak

I have written a very simple test application to try to help with a larger project I'm working on. Simply put, the test app loops a predetermined number of times and appends "1" to a string on each loop. When the loop hits a multiple of 1000, the…
2
votes
5 answers

NSString Format issue automatically append \x

i found something like this was not expected code NSString *strCrown2 = @"T-#-B-DAC"; when i put break point there and check i found like below image There is \x , it is not part of string in console it is displaying T-#-B-DAC it is correct my…
Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
2
votes
1 answer

Which encoding do I need to decrypt this AES128 data

I am using this Objective-C category to encrypt and decrypt my string data: https://gist.github.com/leeprobert/b83f07ca90ad657a1cd17f94b13138b1 and I have an NSString category like so: @implementation NSString (AESCrypt) - (NSString…
Lee Probert
  • 10,308
  • 8
  • 43
  • 70
2
votes
1 answer

How to draw an array of NSStrings on as UIView without any leading space between them and occupies the entire rect?

I want to draw an array of strings of varied font size on a UIView as this.I have calculated the height required for each string to be drawn. The array of string in the example is {"Enter some text", "that", "will fit", "the rect"}. I calculate the…
Murali_kg
  • 51
  • 3
2
votes
2 answers

Displaying content at correct scale in UIWebView on iPad

I have a UIWebView set to scale to fit in an iPad app that gets its content from and NSString. If I turn off scale to fit the text is bigger, although would like it to be much bigger, but I lose the zooming feature. If I set scale to fit on the text…
user7865437
  • 812
  • 14
  • 28
2
votes
2 answers

Always getting the same height using sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

The CGSize returned by sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: contains always the same height. Why is that, and is there a way around this? I want to align a string vertically and it may not be truncated, unless it can't fit…
Rits
  • 5,105
  • 4
  • 42
  • 53
2
votes
2 answers

Vertical bar character appearing oddly within NSString

The vertical bar | character with in a string literal is displaying differently in Xcode as well as on iPad simulator when its rendered. Basically I'm just delimiting a set of values by vertical bar | character as a NSString literal. Objective-C…
dreamweiver
  • 6,002
  • 2
  • 24
  • 39
2
votes
2 answers

iPhone - Check if character is capital

Hey! I was wondering if there was any way to check if the first letter of a string was capital or not in an NSString. Something similar to: if ([[string substringToIndex:1] isCapitalLetter]) { // CODE } --or-- if ([self…
Hank Brekke
  • 2,024
  • 2
  • 24
  • 33
2
votes
1 answer

Compare two file paths in NSStrings including links

I am solving a bug caused by path comparison using -[NSString isEqualToString:] (lldb) po aString /var/mobile/Containers/Bundle/Application/DE14BC26-B07D-46C2-89BF-E800231BAD1F/a.app/b.bundle/epub/OEBPS/Text/02.xhtml (lldb) po…
chubao
  • 5,871
  • 6
  • 39
  • 64
2
votes
1 answer

Which NSCharacterSet describes characters which are valid in a tel: URL?

The NSURL initializer that takes a String is failable, and the documentation says: If the URL string was malformed, returns nil. Attempting to construct a URL with NSURL(string: "tel://+49 00 00 00 00 00") returns…
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97
2
votes
2 answers

Convert quoted strings in a CSV to an NSMutableArray without the quotes

I have a question about the objective C. I have the following NSString *name shown below: "First Name","Second Name","Last Name"; Actually, name is the header of the CSV and receive from the URL. And I use the follow statement to break the…
Questions
  • 20,055
  • 29
  • 72
  • 101
2
votes
3 answers

Why do two NSStrings taken from user input end up with the same address?

I am curious to know how the OS or compiler manages the memory usage. Take this example of a login screen. If I enter the same strings for both user ID & password: say "anoop" both times, the following two strings have same addresses: NSString…
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
2
votes
2 answers

How to use a placeholder with an NSString

I am currently using this code to put some text on the screen userOutput.text=@""; I want to be able to display an int variable in the string, like you do with printf in C with the %d placeholders. How do I do this with an NSString
Regan
  • 1,487
  • 2
  • 28
  • 43
2
votes
1 answer

Dynamically create a NSString stringWithFormat: output

trying to figure out how to add zeroes in front of a random generated number with dynamic length of the number. For example if the number is 10 characters long, I can print the number as stringWithFormat:@"%.10d",i Since the numer can somtimes be…
linge
  • 23
  • 1
  • 1
  • 4
2
votes
2 answers

Is there an easy way to make part of an NSString object a superscript or subscript?

For example, suppose I have an NSString @"20O(2H,1H)19O", and I want all the numbers to be superscript. Is there an easy way to do this?
PTTHomps
  • 1,477
  • 2
  • 22
  • 38
1 2 3
99
100