<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mediawiki.gnustep.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kendall</id>
	<title>GNUstepWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://mediawiki.gnustep.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kendall"/>
	<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php/Special:Contributions/Kendall"/>
	<updated>2026-04-17T22:48:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.7</generator>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSArray&amp;diff=4666</id>
		<title>NSArray</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSArray&amp;diff=4666"/>
		<updated>2007-04-05T00:13:41Z</updated>

		<summary type="html">&lt;p&gt;Kendall: /* Creating Arrays */ added /* See Also */ added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSArray.html#class$NSArray NSArray] is a immutable, integer indexed, array of objects.&lt;br /&gt;
&lt;br /&gt;
== Creating Arrays ==&lt;br /&gt;
&lt;br /&gt;
=== From a List ===&lt;br /&gt;
&lt;br /&gt;
The most common method to create a array is to just pass it a list:&lt;br /&gt;
&lt;br /&gt;
  NSArray *array = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, [NSNull null], @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
When creating arrays remember that any kind of object can be included, but only objects can be included.&lt;br /&gt;
&lt;br /&gt;
=== Copy Array ===&lt;br /&gt;
&lt;br /&gt;
A copy of an array can be done simply by doing the following:&lt;br /&gt;
&lt;br /&gt;
  NSArray *array1 = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, [NSNull null], @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
  NSArray *array2 = [NSArray arrayWithArray: array1];&lt;br /&gt;
&lt;br /&gt;
=== From a Array ===&lt;br /&gt;
&lt;br /&gt;
An array object can be made with a regular array of objects, as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
  id array1[4] = {@&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, [NSNull null], @&amp;quot;Jane&amp;quot;};&lt;br /&gt;
  NSArray *array2 = [NSArray arrayWithObjects: array1 count: 4];&lt;br /&gt;
&lt;br /&gt;
Count being the number of objects from the array to be used.&lt;br /&gt;
&lt;br /&gt;
== Code chunks ==&lt;br /&gt;
&lt;br /&gt;
=== Create index dictionary ===&lt;br /&gt;
&lt;br /&gt;
Following NSArray category method creates a dictionary which works as an index by an attribute of contained objects. It uses [[Key Value Coding]].&lt;br /&gt;
&lt;br /&gt;
 - (NSDictionary *)indexDictionaryForKey:(NSString *)key&lt;br /&gt;
 {&lt;br /&gt;
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];&lt;br /&gt;
    NSDictionary        *retval;&lt;br /&gt;
    NSEnumerator        *enumerator;&lt;br /&gt;
    id                   object;&lt;br /&gt;
 &lt;br /&gt;
    enumerator = [self objectEnumerator];&lt;br /&gt;
 &lt;br /&gt;
    while( (object = [enumerator nextObject]) )&lt;br /&gt;
    {&lt;br /&gt;
        [dict setObject:object forKey:[object valueForKey:key]];&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    retval = [[NSDictionary alloc] initWithDictionary:dict];&lt;br /&gt;
    RELEASE(dict);&lt;br /&gt;
    &lt;br /&gt;
    return AUTORELEASE(retval);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
*[[NSMutableArray]]&lt;br /&gt;
*[[NSEnumerator]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4665</id>
		<title>NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4665"/>
		<updated>2007-04-04T20:53:22Z</updated>

		<summary type="html">&lt;p&gt;Kendall: Broke &amp;quot;Constructing Strings&amp;quot; into subsections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Strings in GNUstep use the [http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSString NSString] class in gnustep-base.&lt;br /&gt;
NSString is a immutable class, meaning it cannot change.&lt;br /&gt;
For mutable strings, see [[NSMutableString]].&lt;br /&gt;
See the reference manual for gnustep-base for more details about NSString.&lt;br /&gt;
&lt;br /&gt;
== Constructing Strings ==&lt;br /&gt;
&lt;br /&gt;
=== Constant Strings ===&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;at&amp;quot; symbol ('@'). For example:&lt;br /&gt;
&lt;br /&gt;
  NSString * myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSLog(myString);&lt;br /&gt;
&lt;br /&gt;
myString is now an NSString object, and can have methods called on it like any other string.&lt;br /&gt;
&lt;br /&gt;
=== Copy Strings ===&lt;br /&gt;
&lt;br /&gt;
You can also make a copy of a string as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSString *newString = [NSString stringWithString: myString];&lt;br /&gt;
&lt;br /&gt;
=== C Strings ===&lt;br /&gt;
&lt;br /&gt;
Or if you already have a C string you can convert it to a NSString object as follows:&lt;br /&gt;
&lt;br /&gt;
  char *myString = &amp;quot;This is a C string.&amp;quot;;&lt;br /&gt;
  ...&lt;br /&gt;
  NSString *NSString newString1 = [NSString stringWithCString: myString encoding: [NSString defaultCStringEncoding]];&lt;br /&gt;
  // Or:&lt;br /&gt;
  NSString *NSString newString2 = [NSString stringWithUTF8String: myString];&lt;br /&gt;
&lt;br /&gt;
Note that using [NSString stringWithCString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
=== Formated Strings ===&lt;br /&gt;
&lt;br /&gt;
A more flexable way of creating a string, using C style format flags follows:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = [NSString stringWithFormat: @&amp;quot;This is an%@ of a string with %d integer.&amp;quot;, @&amp;quot; example&amp;quot;, 1];&lt;br /&gt;
&lt;br /&gt;
== Getting a C String ==&lt;br /&gt;
&lt;br /&gt;
You can convert an NSString object to a plain C string using the cStringUsingEncoding: method. For example:&lt;br /&gt;
&lt;br /&gt;
  NSString *newString = @&amp;quot;This is a test string.&amp;quot;;&lt;br /&gt;
  char     *theString;&lt;br /&gt;
 &lt;br /&gt;
  theString = [newString cStringWithEncoding:[NSString defaultCStringEncoding]];&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
  theString = [newString UTF8String];&lt;br /&gt;
&lt;br /&gt;
Note that using [string cString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
== Reading and Writing Files With String ==&lt;br /&gt;
&lt;br /&gt;
The following example shows how you would use files with NSString:&lt;br /&gt;
&lt;br /&gt;
  // Read in the file.&lt;br /&gt;
  NSString *aString = [NSString stringWithContentsOfFile: @&amp;quot;infile.txt&amp;quot;];&lt;br /&gt;
  // Do something with our new string.&lt;br /&gt;
  aString = ''doSomething''(aString);&lt;br /&gt;
  // And finally save our changes to a file.&lt;br /&gt;
  if([aString writeToFile: @&amp;quot;outfile&amp;quot; atomically: YES])&lt;br /&gt;
    // Success code.&lt;br /&gt;
  else&lt;br /&gt;
    // Error code.&lt;br /&gt;
&lt;br /&gt;
== Substrings ==&lt;br /&gt;
&lt;br /&gt;
If you have a delimiter for breaking the string up, the easiest method to use would be the [string componentsSeparatedByString:] method.&lt;br /&gt;
The following example demonstrates this:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  NSArray *strings = [string componentsSeparatedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // give us the array {@&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
An array of string can also be joined together with the [array componentsJoinedByString:] method as follows:&lt;br /&gt;
&lt;br /&gt;
  NSArray *strings = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
  NSString *string = [strings componentsJoinedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // creating the string @&amp;quot;John, Bob, Jane&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you need something more advanced [[NSScanner]] will be need.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
One the other hand, if you know the indexes ahead of time one of three substring methods could be used, as demonstrated in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringFromIndex: 6]);&lt;br /&gt;
  // Get the last six characters in the string (&amp;quot;, Jane&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringToIndex: 6]);&lt;br /&gt;
  // Get the first six characters in the string (&amp;quot;John, &amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSRange range = {3, 6};&lt;br /&gt;
  NSLog([string substringWithRange: range]);&lt;br /&gt;
  // Starting at index three get a string of length six (&amp;quot;hn, Bo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
[[http://www.gnustep.org/resources/documentation/Developer/Base/Reference/TypesAndConstants.html#type$NSRange NSRange]] is a structure used mainly in string and arrays, defining the beginning index and the offset.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSMutableString&amp;diff=4664</id>
		<title>NSMutableString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSMutableString&amp;diff=4664"/>
		<updated>2007-04-04T20:43:17Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSMutableString NSMutableString] inherits from [[NSString]], but includes methods for changing the string.&lt;br /&gt;
&lt;br /&gt;
== Editing Strings ==&lt;br /&gt;
&lt;br /&gt;
=== Adding To Strings ===&lt;br /&gt;
&lt;br /&gt;
Strings can be added on to by appending the new substring to the end, or by inserting it any where in the middle.&lt;br /&gt;
&lt;br /&gt;
==== Appending Strings ====&lt;br /&gt;
&lt;br /&gt;
The simplest way to edit a string is by appending to the end of the string, as shown here:&lt;br /&gt;
&lt;br /&gt;
  NSMutableString *str = @&amp;quot;short string&amp;quot;;&lt;br /&gt;
  [str appendString: @&amp;quot; made longer&amp;quot;];&lt;br /&gt;
  // str is now = @&amp;quot;short string made longer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
C style formating flags can also be used as follows:&lt;br /&gt;
&lt;br /&gt;
  NSMutableString *str = @&amp;quot;short string&amp;quot;;&lt;br /&gt;
  [str appendFormat: @&amp;quot; made longer %@.&amp;quot;, @&amp;quot;with formating&amp;quot;];&lt;br /&gt;
  // str is now = @&amp;quot;short string made longer with formating.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Inserting Substrings ====&lt;br /&gt;
&lt;br /&gt;
The more advanced method of adding to strings in by insertion, as demonstrated here:&lt;br /&gt;
&lt;br /&gt;
  NSMutableString *str = @&amp;quot;a string&amp;quot;;&lt;br /&gt;
  [str insertString: @&amp;quot;new &amp;quot; atIndex: 2];&lt;br /&gt;
  // str is now = @&amp;quot;a new string&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Replacing Substrings ===&lt;br /&gt;
&lt;br /&gt;
A certain substring can be replaced with a new one as follows:&lt;br /&gt;
&lt;br /&gt;
  NSMutableString *str = @&amp;quot;a old string&amp;quot;;&lt;br /&gt;
  [str replaceString: @&amp;quot;old&amp;quot; withString: @&amp;quot;new];&lt;br /&gt;
  // str is now = @&amp;quot;a new string&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This can also be done with ranges:&lt;br /&gt;
&lt;br /&gt;
  NSMutableString *str = @&amp;quot;a old string&amp;quot;;&lt;br /&gt;
  NSRange range = {2, 3};&lt;br /&gt;
  // start at index 2 and include the next 3 characters&lt;br /&gt;
  [str replaceCharactersInRange: range withString: @&amp;quot;new];&lt;br /&gt;
  // str is now = @&amp;quot;a new string&amp;quot;&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4660</id>
		<title>NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4660"/>
		<updated>2007-04-04T18:59:42Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Strings in GNUstep use the [http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSString NSString] class in gnustep-base.&lt;br /&gt;
NSString is a immutable class, meaning it cannot change.&lt;br /&gt;
For mutable strings, see [[NSMutableString]].&lt;br /&gt;
See the reference manual for gnustep-base for more details about NSString.&lt;br /&gt;
&lt;br /&gt;
== Constructing Strings ==&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;at&amp;quot; symbol ('@'). For example:&lt;br /&gt;
&lt;br /&gt;
  NSString * myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSLog(myString);&lt;br /&gt;
&lt;br /&gt;
myString is now an NSString object, and can have methods called on it like any other string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can also make a copy of a string as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSString *newString = [NSString stringWithString: myString];&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or if you already have a C string you can convert it to a NSString object as follows:&lt;br /&gt;
&lt;br /&gt;
  char *myString = &amp;quot;This is a C string.&amp;quot;;&lt;br /&gt;
  ...&lt;br /&gt;
  NSString *NSString newString1 = [NSString stringWithCString: myString encoding: [NSString defaultCStringEncoding]];&lt;br /&gt;
  // Or:&lt;br /&gt;
  NSString *NSString newString2 = [NSString stringWithUTF8String: myString];&lt;br /&gt;
&lt;br /&gt;
Note that using [NSString stringWithCString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A more flexable way of creating a string, using C style format flags follows:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = [NSString stringWithFormat: @&amp;quot;This is an%@ of a string with %d integer.&amp;quot;, @&amp;quot; example&amp;quot;, 1];&lt;br /&gt;
&lt;br /&gt;
== Getting a C String ==&lt;br /&gt;
&lt;br /&gt;
You can convert an NSString object to a plain C string using the cStringUsingEncoding: method. For example:&lt;br /&gt;
&lt;br /&gt;
  NSString *newString = @&amp;quot;This is a test string.&amp;quot;;&lt;br /&gt;
  char     *theString;&lt;br /&gt;
 &lt;br /&gt;
  theString = [newString cStringWithEncoding:[NSString defaultCStringEncoding]];&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
  theString = [newString UTF8String];&lt;br /&gt;
&lt;br /&gt;
Note that using [string cString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
== Reading and Writing Files With String ==&lt;br /&gt;
&lt;br /&gt;
The following example shows how you would use files with NSString:&lt;br /&gt;
&lt;br /&gt;
  // Read in the file.&lt;br /&gt;
  NSString *aString = [NSString stringWithContentsOfFile: @&amp;quot;infile.txt&amp;quot;];&lt;br /&gt;
  // Do something with our new string.&lt;br /&gt;
  aString = ''doSomething''(aString);&lt;br /&gt;
  // And finally save our changes to a file.&lt;br /&gt;
  if([aString writeToFile: @&amp;quot;outfile&amp;quot; atomically: YES])&lt;br /&gt;
    // Success code.&lt;br /&gt;
  else&lt;br /&gt;
    // Error code.&lt;br /&gt;
&lt;br /&gt;
== Substrings ==&lt;br /&gt;
&lt;br /&gt;
If you have a delimiter for breaking the string up, the easiest method to use would be the [string componentsSeparatedByString:] method.&lt;br /&gt;
The following example demonstrates this:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  NSArray *strings = [string componentsSeparatedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // give us the array {@&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
An array of string can also be joined together with the [array componentsJoinedByString:] method as follows:&lt;br /&gt;
&lt;br /&gt;
  NSArray *strings = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
  NSString *string = [strings componentsJoinedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // creating the string @&amp;quot;John, Bob, Jane&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you need something more advanced [[NSScanner]] will be need.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
One the other hand, if you know the indexes ahead of time one of three substring methods could be used, as demonstrated in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringFromIndex: 6]);&lt;br /&gt;
  // Get the last six characters in the string (&amp;quot;, Jane&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringToIndex: 6]);&lt;br /&gt;
  // Get the first six characters in the string (&amp;quot;John, &amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSRange range = {3, 6};&lt;br /&gt;
  NSLog([string substringWithRange: range]);&lt;br /&gt;
  // Starting at index three get a string of length six (&amp;quot;hn, Bo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
[[http://www.gnustep.org/resources/documentation/Developer/Base/Reference/TypesAndConstants.html#type$NSRange NSRange]] is a structure used mainly in string and arrays, defining the beginning index and the offset.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4659</id>
		<title>NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4659"/>
		<updated>2007-04-04T03:45:53Z</updated>

		<summary type="html">&lt;p&gt;Kendall: Added substring section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Strings in GNUstep use the [http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSString NSString] class in gnustep-base. See the reference manual for gnustep-base for more details about NSString.&lt;br /&gt;
&lt;br /&gt;
== Constructing Strings ==&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;at&amp;quot; symbol ('@'). For example:&lt;br /&gt;
&lt;br /&gt;
  NSString * myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSLog(myString);&lt;br /&gt;
&lt;br /&gt;
myString is now an NSString object, and can have methods called on it like any other string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can also make a copy of a string as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSString *newString = [NSString stringWithString: myString];&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or if you already have a C string you can convert it to a NSString object as follows:&lt;br /&gt;
&lt;br /&gt;
  char *myString = &amp;quot;This is a C string.&amp;quot;;&lt;br /&gt;
  ...&lt;br /&gt;
  NSString *NSString newString1 = [NSString stringWithCString: myString encoding: [NSString defaultCStringEncoding]];&lt;br /&gt;
  // Or:&lt;br /&gt;
  NSString *NSString newString2 = [NSString stringWithUTF8String: myString];&lt;br /&gt;
&lt;br /&gt;
Note that using [NSString stringWithCString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A more flexable way of creating a string, using C style format flags follows:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = [NSString stringWithFormat: @&amp;quot;This is an%@ of a string with %d integer.&amp;quot;, @&amp;quot; example&amp;quot;, 1];&lt;br /&gt;
&lt;br /&gt;
== Getting a C String ==&lt;br /&gt;
&lt;br /&gt;
You can convert an NSString object to a plain C string using the cStringUsingEncoding: method. For example:&lt;br /&gt;
&lt;br /&gt;
  NSString *newString = @&amp;quot;This is a test string.&amp;quot;;&lt;br /&gt;
  char     *theString;&lt;br /&gt;
 &lt;br /&gt;
  theString = [newString cStringWithEncoding:[NSString defaultCStringEncoding]];&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
  theString = [newString UTF8String];&lt;br /&gt;
&lt;br /&gt;
Note that using [string cString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
== Reading and Writing Files With String ==&lt;br /&gt;
&lt;br /&gt;
The following example shows how you would use files with NSString:&lt;br /&gt;
&lt;br /&gt;
  // Read in the file.&lt;br /&gt;
  NSString *aString = [NSString stringWithContentsOfFile: @&amp;quot;infile.txt&amp;quot;];&lt;br /&gt;
  // Do something with our new string.&lt;br /&gt;
  aString = ''doSomething''(aString);&lt;br /&gt;
  // And finally save our changes to a file.&lt;br /&gt;
  if([aString writeToFile: @&amp;quot;outfile&amp;quot; atomically: YES])&lt;br /&gt;
    // Success code.&lt;br /&gt;
  else&lt;br /&gt;
    // Error code.&lt;br /&gt;
&lt;br /&gt;
== Substrings ==&lt;br /&gt;
&lt;br /&gt;
If you have a delimiter for breaking the string up, the easiest method to use would be the [string componentsSeparatedByString:] method.&lt;br /&gt;
The following example demonstrates this:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  NSArray *strings = [string componentsSeparatedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // give us the array {@&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
An array of string can also be joined together with the [array componentsJoinedByString:] method as follows:&lt;br /&gt;
&lt;br /&gt;
  NSArray *strings = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
  NSString *string = [strings componentsJoinedByString: @&amp;quot;, &amp;quot;];&lt;br /&gt;
  // creating the string @&amp;quot;John, Bob, Jane&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you need something more advanced [[NSScanner]] will be need.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
One the other hand, if you know the indexes ahead of time one of three substring methods could be used, as demonstrated in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *string = @&amp;quot;John, Bob, Jane&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringFromIndex: 6]);&lt;br /&gt;
  // Get the last six characters in the string (&amp;quot;, Jane&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSLog([string substringToIndex: 6]);&lt;br /&gt;
  // Get the first six characters in the string (&amp;quot;John, &amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  NSRange range = {3, 6};&lt;br /&gt;
  NSLog([string substringWithRange: range]);&lt;br /&gt;
  // Starting at index three get a string of length six (&amp;quot;hn, Bo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
[[http://www.gnustep.org/resources/documentation/Developer/Base/Reference/TypesAndConstants.html#type$NSRange NSRange]] is a structure used mainly in string and arrays, defining the beginning index and the offset.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4657</id>
		<title>NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4657"/>
		<updated>2007-04-04T00:54:21Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Strings in GNUstep use the [http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSString.html#class$NSString NSString] class in gnustep-base. See the reference manual for gnustep-base for more details about NSString.&lt;br /&gt;
&lt;br /&gt;
== Constructing Strings ==&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;at&amp;quot; symbol ('@'). For example:&lt;br /&gt;
&lt;br /&gt;
  NSString * myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSLog(myString);&lt;br /&gt;
&lt;br /&gt;
myString is now an NSString object, and can have methods called on it like any other string.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
You can also make a copy of a string as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSString *newString = [NSString stringWithString: myString];&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Or if you already have a C string you can convert it to a NSString object as follows:&lt;br /&gt;
&lt;br /&gt;
  char *myString = &amp;quot;This is a C string.&amp;quot;;&lt;br /&gt;
  ...&lt;br /&gt;
  NSString *NSString newString1 = [NSString stringWithCString: myString encoding: [NSString defaultCStringEncoding]];&lt;br /&gt;
  // Or:&lt;br /&gt;
  NSString *NSString newString2 = [NSString stringWithUTF8String: myString];&lt;br /&gt;
&lt;br /&gt;
Note that using [NSString stringWithCString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A more flexable way of creating a string, using C style format flags follows:&lt;br /&gt;
&lt;br /&gt;
  NSString *myString = [NSString stringWithFormat: @&amp;quot;This is an%@ of a string with %d integer.&amp;quot;, @&amp;quot; example&amp;quot;, 1];&lt;br /&gt;
&lt;br /&gt;
== Getting a C String ==&lt;br /&gt;
&lt;br /&gt;
You can convert an NSString object to a plain C string using the cStringUsingEncoding: method. For example:&lt;br /&gt;
&lt;br /&gt;
  NSString *newString = @&amp;quot;This is a test string.&amp;quot;;&lt;br /&gt;
  char     *theString;&lt;br /&gt;
 &lt;br /&gt;
  theString = [newString cStringWithEncoding:[NSString defaultCStringEncoding]];&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
  theString = [newString UTF8String];&lt;br /&gt;
&lt;br /&gt;
Note that using [string cString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
== Reading and Writing Files With String ==&lt;br /&gt;
&lt;br /&gt;
The following example shows how you would use files with NSString:&lt;br /&gt;
&lt;br /&gt;
  // Read in the file.&lt;br /&gt;
  NSString *aString = [NSString stringWithContentsOfFile: @&amp;quot;infile.txt&amp;quot;];&lt;br /&gt;
  // Do something with our new string.&lt;br /&gt;
  aString = ''doSomething''(aString);&lt;br /&gt;
  // And finally save our changes to a file.&lt;br /&gt;
  if([aString writeToFile: @&amp;quot;outfile&amp;quot; atomically: YES])&lt;br /&gt;
    // Success code.&lt;br /&gt;
  else&lt;br /&gt;
    // Error code.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=Talk:NSString&amp;diff=4656</id>
		<title>Talk:NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=Talk:NSString&amp;diff=4656"/>
		<updated>2007-04-04T00:50:15Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I have changed the &amp;quot;Constant Strings&amp;quot; section to the &amp;quot;Constructing Strings&amp;quot; section, and add more ways to create a string object.&lt;br /&gt;
&lt;br /&gt;
--[[User:Kendall|Kendall]] 02:50, 4 April 2007 (CEST)&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSEnumerator&amp;diff=4653</id>
		<title>NSEnumerator</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSEnumerator&amp;diff=4653"/>
		<updated>2007-04-03T20:36:18Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSEnumerator.html#class$NSEnumerator&lt;br /&gt;
&lt;br /&gt;
NSEnumerator in gnustep-base allow for iteration over collection.&lt;br /&gt;
&lt;br /&gt;
== Using NSEnumerator ==&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates the use of NSEnumerator with an [[NSArray]] object:&lt;br /&gt;
&lt;br /&gt;
  NSArray *aArray = [NSArray arrayWithObjects: @&amp;quot;John&amp;quot;, @&amp;quot;Bob&amp;quot;, @&amp;quot;Jane&amp;quot;];&lt;br /&gt;
  NSEnumerator *enumerator = [aArray objectEnumerator];&lt;br /&gt;
  id obj;&lt;br /&gt;
  &lt;br /&gt;
  while(obj = [enumerator nextObject])&lt;br /&gt;
    doSomethingWithObject( obj );&lt;br /&gt;
&lt;br /&gt;
== Getting an NSEnumerator from a Collection ==&lt;br /&gt;
&lt;br /&gt;
The [[NSArray]], [[NSSet]], and [[NSDictionary]] collection objects all include the -objectEnumerator method.&lt;br /&gt;
[[NSDictionary]] also includes -keyEnumerator, which enumerates over the dictionary keys instead of the objects.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
	<entry>
		<id>https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4652</id>
		<title>NSString</title>
		<link rel="alternate" type="text/html" href="https://mediawiki.gnustep.org/index.php?title=NSString&amp;diff=4652"/>
		<updated>2007-04-03T18:55:57Z</updated>

		<summary type="html">&lt;p&gt;Kendall: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;http://www.gnustep.org/resources/documentation/Developer/Base/Reference/index.html&lt;br /&gt;
&lt;br /&gt;
Strings in GNUstep use the NSString class in gnustep-base. See the reference manual for gnustep-base for more details about NSString.&lt;br /&gt;
&lt;br /&gt;
== Constant Strings ==&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;at&amp;quot; symbol ('@'). For example:&lt;br /&gt;
&lt;br /&gt;
  NSString * myString = @&amp;quot;This is an example of a string.&amp;quot;;&lt;br /&gt;
  NSLog(myString);&lt;br /&gt;
&lt;br /&gt;
myString is now an NSString object, and can have methods called on it like any other string.&lt;br /&gt;
&lt;br /&gt;
== Getting a C String ==&lt;br /&gt;
&lt;br /&gt;
You can convert an NSString object to a plain C string using the cStringUsingEncoding: method. For example:&lt;br /&gt;
&lt;br /&gt;
  NSString *newString = @&amp;quot;This is a test string.&amp;quot;;&lt;br /&gt;
  char     *theString;&lt;br /&gt;
 &lt;br /&gt;
  theString = [newString cStringWithEncoding:[NSString defaultCStringEncoding]];&lt;br /&gt;
&lt;br /&gt;
or:&lt;br /&gt;
&lt;br /&gt;
  theString = [newString UTF8String];&lt;br /&gt;
&lt;br /&gt;
Note that using [string cString] is deprecated!&lt;br /&gt;
&lt;br /&gt;
== Reading and Writing Files With String ==&lt;br /&gt;
&lt;br /&gt;
The following example shows how you would use files with NSString:&lt;br /&gt;
&lt;br /&gt;
  // Read in the file.&lt;br /&gt;
  NSString *aString = [NSString stringWithContentsOfFile: @&amp;quot;infile.txt&amp;quot;];&lt;br /&gt;
  // Do something with our new string.&lt;br /&gt;
  aString = ''doSomething''(aString);&lt;br /&gt;
  // And finally save our changes to a file.&lt;br /&gt;
  if([aString writeToFile: @&amp;quot;outfile&amp;quot; atomically: YES])&lt;br /&gt;
    // Success code.&lt;br /&gt;
  else&lt;br /&gt;
    // Error code.&lt;br /&gt;
&lt;br /&gt;
[[Category:Foundation]]&lt;br /&gt;
[[Category:Snippets]]&lt;/div&gt;</summary>
		<author><name>Kendall</name></author>
	</entry>
</feed>