I want to take all values after a new line character \n
from my string. How can I get those values?
rsplit() method to get everything after the last slash in a string. The str. rsplit method returns a list of the words in the string using the provided separator as the delimiter string. Copied!
Using split() to get string after occurrence of given substring. The split function can also be applied to perform this particular task, in this function, we use the power of limiting the split and then print the later string.
Adding Newline Characters in a String Operating systems have special characters denoting the start of a new line. For example, in Linux a new line is denoted by “\n”, also called a Line Feed. In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF.
To extract part string between two different characters, you can do as this: Select a cell which you will place the result, type this formula =MID(LEFT(A1,FIND(">",A1)-1),FIND("<",A1)+1,LEN(A1)), and press Enter key. Note: A1 is the text cell, > and < are the two characters you want to extract string between.
Try this:
NSString *substring = nil;
NSRange newlineRange = [yourString rangeOfString:@"\n"];
if(newlineRange.location != NSNotFound) {
substring = [yourString substringFromIndex:newlineRange.location];
}
Take a look at method componentsSeparatedByString
here.
A quick example taken from reference:
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
this will produce a NSArray
with strings separated: { @"Norman", @"Stanley", @"Fletcher" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With