34,333
edits
Changes
→Checking for String Prefixes and Suffixes
== Checking for String Prefixes and Suffixes ==
A string object can be tested to identify whether the string begins or ends with a particular sequence of characters (otherwise known as prefixes and suffixes). This is achieved using the ''hasPrefix'' and ''hasSuffix'' methods respectively, both of which return boolean values on whether a match is found or not.
<pre>
NSString *string1 = @"The quick brown fox jumped";
BOOL result;
result = [string1 hasPrefix: @"The"];
if (result)
NSLog (@"String begins with The");
result = [string1 hasSuffix: @"dog"];
if (result)
NSLog (@"String ends with dog");
</pre>
== Converting to Upper or Lower Case ==