Difference between revisions of "NSString"

From GNUstepWiki
Jump to navigation Jump to search
(Added some details to encourage additions)
 
Line 3: Line 3:
 
== Constant Strings ==
 
== Constant Strings ==
  
As in plain C, you can create strings in GNUstep that automatically flatten out to be static instances of NSString. This is done by preceding the quoted string by an "at" symbol ('@'). For example:
+
As you can create static instances of char* plain C, you can create strings in GNUstep that automatically flatten out to be static instances of NSString. This is done by preceding the quoted string by an "at" symbol ('@'). For example:
  
 
   NSString * myString = @"This is an example of a string.";
 
   NSString * myString = @"This is an example of a string.";
 
   NSLog(myString);
 
   NSLog(myString);
 +
 +
myString is now an NSString object, and can have methods called on it like any other string.
 +
 +
== Getting a C String ==
 +
 +
You can convert an NSString object to a plain C string using the cString method. For example:
 +
 +
  NSString* newString = @"This is a test string.";
 +
  char* theString = [newString cString];

Revision as of 06:34, 22 November 2005

Strings in GNUstep use the NSString class in gnustep-base. See the reference manual for gnustep-base for more details about NSString.

Constant Strings

As you can create static instances of char* plain C, you can create strings in GNUstep that automatically flatten out to be static instances of NSString. This is done by preceding the quoted string by an "at" symbol ('@'). For example:

 NSString * myString = @"This is an example of a string.";
 NSLog(myString);

myString is now an NSString object, and can have methods called on it like any other string.

Getting a C String

You can convert an NSString object to a plain C string using the cString method. For example:

 NSString* newString = @"This is a test string.";
 char* theString = [newString cString];