Created
January 19, 2010 12:16
-
-
Save MylesHarding/280900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// string-manipulation-in-objective-c | |
// public gist - free to use | |
// Concatenation | |
// The advantage of this method is that it is simple to put text between the two strings | |
// (e.g. Put a "-" replace %@%@ by %@ - %@ and that will put a dash between stringA and stringB | |
- (NSString*) concatenateString:(NSString*)stringA withString:(NSString*)stringB { | |
NSString *finalString = [NSString stringWithFormat:@"%@%@", stringA, stringB]; | |
return finalString; | |
} | |
// String Length: | |
// Not sure for east-asian languages, but works fine usually | |
- (int) stringLength:(NSString*)string { | |
return [string length]; | |
} | |
// Remove text from string: | |
- (NSString*)remove:(NSString*)textToRemove fromString:(NSString*)input { | |
return [input stringByReplacingOccurrencesOfString:textToRemove withString:@""]; | |
} | |
// Uppercase / Lowercase / Titlecase: | |
// I'm not sure for Titlecase | |
- (NSString*)uppercase:(NSString*)stringToUppercase { | |
return [stringToUppercase upercaseString]; | |
} | |
- (NSString*)lowercase:(NSString*)stringToLowercase { | |
return [stringToUppercase lowercaseString]; | |
} | |
// Find/Replace | |
- (NSString*)findInString:(NSString*)string replaceWithString:(NSString*)stringToReplaceWith { | |
return [input stringByReplacingOccurrencesOfString:string withString:stringToReplaceWith]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment