Working with strings – Apple WebObjects 3.5 User Manual
Page 191

Working With Strings
191
Note:
The configuration of your HTTP server determines the user who owns
autostarted applications.
Reading From Files
The string, array, and dictionary classes provide methods of the form
classNameWithContentsOfFile:
. These methods create a new object and initialize it
with the contents of a specified file, which can be specified with a full or
relative pathname.
Working With Strings
NSString and NSMutableString objects represent static and dynamic
character strings, respectively. They may be searched for substrings,
compared with one another, combined into new strings, and so on.
The difference between NSStrings and NSMutableStrings is that you can’t
change an NSString’s contents from its initial character string. While
NSMutableString provides methods such as
appendString:
and
setString:
to add
to or replace the string’s contents, there are no such methods available for
NSStrings. It’s best to use NSStrings wherever possible. Only use an
NSMutableString if you need to modify its contents after you create it.
You can create NSStrings with WebScript’s at sign (@) syntax for defining
constant objects. For example, the following statement creates an NSString
object:
id msg = @"This option is no longer available. Please choose another.";
You can also create string objects with creation methods—methods whose
names are preceded by a + and that return new objects. The strings created
with the @ syntax are always NSStrings, so they can’t be modified. If you
use a creation method instead, you can choose to create either an NSString
or a NSMutableString. The following code excerpt illustrates the creation
of both NSString and NSMutableString objects:
// Create an immutable string
id message = [NSString stringWithString:@"Hi"];
// Create a mutable string
id message = [NSMutableString stringWithString:@"Hi"];
The methods provided by NSString and NSMutableString are described in
more detail in the next section.