Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get values after "\n" character?

I want to take all values after a new line character \n from my string. How can I get those values?

like image 809
Ankit Vyas Avatar asked Jun 04 '11 02:06

Ankit Vyas


People also ask

How do you get all the items after a character in Python?

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!

How do you get a string after a specific character in Python?

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.

What is the use of \n in a 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.

How do I extract a string between two characters?

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.


2 Answers

Try this:

NSString *substring = nil;
NSRange newlineRange = [yourString rangeOfString:@"\n"];
if(newlineRange.location != NSNotFound) {
  substring = [yourString substringFromIndex:newlineRange.location];
}
like image 121
Jacob Relkin Avatar answered Sep 28 '22 00:09

Jacob Relkin


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" }

like image 32
Jack Avatar answered Sep 27 '22 22:09

Jack