Skip to content

Instantly share code, notes, and snippets.

@MylesHarding
Created January 19, 2010 12:16
Show Gist options
  • Save MylesHarding/280900 to your computer and use it in GitHub Desktop.
Save MylesHarding/280900 to your computer and use it in GitHub Desktop.
// 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