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

Remove repeating substring from string

I cannot think of the a function to remove a repeating substring from my string. My string looks like this: "Rutger Roger rented a testitem zero dollars from Rutger." And if is followed by…
Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67
2
votes
1 answer

How to convert String to code in Objective-C

I need to ask, how can I convert a string containing a piece of code to actual runnable code: int x = 7; int y = 9; NSString *myCode = @"if(x > y) return x; else return y;"; I need to be able to run myCode as actual Objective C code. The…
coder
  • 5,200
  • 3
  • 20
  • 45
2
votes
3 answers

NSString is not appearing properly

I have the following NSString: NSString* searchURL = [NSString…
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
2
votes
1 answer

Best way to display barcodes from NSString

Just wondering what is the best way to display a barcode given a string on the iPhone. I have looked over stackoverflow and google and a few people have different ways each requiring a decent amount of work (I think) and also slightly old so I…
Rudiger
  • 6,749
  • 13
  • 51
  • 102
2
votes
1 answer

Force update of NSTextField

I have a NSTextField that gets updated when my app searches through an array: for (NSString *file in fileinDir) { processedFiles = processedFiles + 1; NSArray*filesinDevice = [fm contentsOfDirectoryAtPath:[[dict…
Pripyat
  • 2,937
  • 2
  • 35
  • 69
2
votes
2 answers

stringWithFormat: with unknown datatype

I am making a framework and I have this code (conditions is an NSDictionary): for (NSString *key in conditions) { id value = [[conditions valueForKey:key] retain]; // Check if number or string if ([value class] == [NSString class]) { …
user142019
2
votes
1 answer

Unicode Hex Character code in NSString not displaying

I have Unicode Hex Character Code 🚂 that I receive from a server request, and I want to convert it to the Steam Locomotive emoji in my UILabel. I have read many other posts on the issue, but none of the solutions seem to work. I have read…
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
2
votes
3 answers

Writing a string to disk in OPENSTEP (YellowBox)

I'm debugging an old OPENSTEP (YellowBox) app, written in Objective-C, running on Windows 2000, built with Project Builder. The only easy way I can find to write a string to disk in Obj-C is [NSString writeToFile], a Cocoa/iOS-era method which…
Dov
  • 15,530
  • 13
  • 76
  • 177
2
votes
4 answers

How to show Bold and Italic both to My NSString without ThirdParty Libary in Objective-c

Here is my code which I attempt : NSString *strFirst = [NSString stringWithFormat:@"The App feature is only available to users while at "]; NSString *strAreaName = kAreaName; NSRange boldedRange = [strAreaName…
Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
2
votes
2 answers

iphone NSString directly use cause memory leaks?

For NSString, we can use NSString *str = [[NSString alloc] initWithString:@"hi"] NSString *str = [NSString stringWithString:@"hi"]; NSString *str = @"hi"; Can someone pls told me in the form of point 3, whether str own @"hi"? I mean whether I…
Jack
  • 3,913
  • 8
  • 41
  • 66
2
votes
3 answers

'-[__NSArrayM _fastCStringContents:]: unrecognized selector sent to instance

I keep getting a unrecognized selector when I try to add an object to my mutable array, I'm trying to add and remove items to a mutable array when a cell is selected in my tableview, here is my code: @interface SomeViewController @property…
jckly
  • 831
  • 1
  • 11
  • 22
2
votes
3 answers

parsing a URL link into segments

http://180.160.1.140/webapp/camera?id=fksmf84-8493-45u3 How to get this url part fksmf84-8493-45u3?? -- this part is keep changing on run time. This is what i have tried so far. NSString *url = @"http://180.160.1.140/webapp/camera?id="; NSArray…
DDDDD
  • 55
  • 7
2
votes
3 answers

How to convert printed dictionary to NSDictionary?

When I NSLog a dictionary output is this: { accounts = ( { "account_number" = 9000012; "account_type" = "Saver Account"; ato = 0; balance = "0.0"; }, { …
Bernard
  • 4,240
  • 18
  • 55
  • 88
2
votes
2 answers

Get Encoding type of NSData

I have some chunks of data that are encoded with random techniques, say first chunk is encoded by NSUTF8StringEncoding another one with NSASCIIStringEncoding or kCFStringEncodingWindowsArabic. I don't know which chunk is encoded with which type of…
Muhammad Burhan
  • 145
  • 1
  • 2
  • 11
2
votes
2 answers

Could not cast value of type 'Swift._NSContiguousString' to 'NSNumber

if let userID = NSUserDefaults.standardUserDefaults().valueForKey("uid") as? String{ currentUser = User(name: snapshot.value["name"] as! String ,phoneNumber: snapshot.value["phoneNumber"] as! String, userId: userID , isOnline:…
jerem
  • 1,016
  • 2
  • 12
  • 27
1 2 3
99
100