I’m having a hard time with trimming some characters from a NSString. Given an existing text view with text in it, the requirements are:
- Trim leading spaces and newlines (Basically ignore any leading whitespace and newlines)
- Copy up to max of 48 chars into the new string OR until a newline is encountered.
I have found that I could do the first requirement from another SO question here with the code:
NSRange range = [textView.text rangeOfString:@"^\\s*" options:NSRegularExpressionSearch];
NSString *result = [textView.text stringByReplacingCharactersInRange:range withString:@""];
However, I’m having trouble with doing the 2nd requirement. Thank you!
This will do what your looking to do. Also it is an easier way to trim leading whitespace and newlines.