Re: NSMutableString Exemplars
Re: NSMutableString Exemplars
- Subject: Re: NSMutableString Exemplars
- From: Lorenzo <email@hidden>
- Date: Wed, 03 Dec 2003 15:24:38 +0100
Hi,
please find here below a list of useful ("Exemplars") methods.
Anyway they are well documented at the NSMutableString class.
You could do that: write "NSMutableString" in your code somewhere. Then
double click on this word "NSMutableString" holding down the Option key and
you will be taken to the NSMutableString documentation.
As far searching and parsing you should take a look at the parent class
NSString. NSMutableString is a subclass of NSString, so it inherits the
NSString's methods.
--
you can create a NSMutableString this way:
mString = [NSMutableString string];
no need to be released
--
or you can create a NSMutableString this way too:
mString = [[NSMutableString alloc] init];
needs to be released
--
then you can set it with
[mString setString:@"john"];
so mString will contain "john"
--
you can append other strings to john with
[mString appendString:@" smiths"];
so mString will contain "john smiths"
--
to delete a character (e.g. delete the last "s" of smiths)
[mString deleteCharactersInRange:NSMakeRange([mString length] - 1, 1)];
so mString will contain "john smiths"
--
to replace all the occurrences in the whole string
(e.g. replacing " " with "_")
[mString replaceOccurrencesOfString:@" " withString:@"_" options:nil
range:NSMakeRange(0, [mString length])];
so mString will contain "john_smith"
--
to extract a substring by a range
NSRange selectedRange = NSMakeRange(2, 4);
NSString *subString = [mString substringWithRange:selectedRange];
so subString will contain "hn_s"
--
to extract a substring from the left to a given position
[mString substringToIndex:4];
so mString will contain "john"
--
to check if mString contains the substring @"ohn"
if(!NSEqualRanges([mString rangeOfString:@"ohn"
options:NSCaseInsensitiveSearch], NSMakeRange(NSNotFound, 0)))
if YES, mString contains the substring @"ohn"
I hope this could help you to start.
Best Regards
--
Lorenzo
email: email@hidden
>
Message: 5
>
To: email@hidden
>
From: Saul Iversen <email@hidden>
>
Subject: NSMutableString Exemplars
>
Date: Wed, 3 Dec 2003 00:39:54 -0500
>
>
Anyone have some good examples of how to manipulate NSMutableStrings?
>
I'm looking for things like substring searching, parsing, and the like.
>
Call me stupid but I can't seem to find anything in the Developer
>
documentation that I am able to assimilate and make use of in a
>
reasonable amount of time. If there is an obvious article beyond the
>
link shown below please share it. Even if you could just type up a
>
really simple example right here in a short period of time, that would
>
be great. Show me how to create str2 out of the first X bytes of str1
>
and the follow up by compressing str1 after removing those leading X
>
bytes. If this question doesn't belong in this forum please forgive me.
>
>
http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/
>
index.html#//apple_ref/doc/uid/10000035i
>
>
Ok that's hopefully my last noob question for the day... :)
>
>
Thanks again,
>
Saul
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.