Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string by delimiter

I really can't find this answer...

I have multiline NSString called myString in XCode, and it is a HTML code. I need to navigate the string by lines, for example:

myString = @"<html>"
            "<body>"
            "<head><title>My Page</title>";

How can I access line per line? like:

LineOne = myString.Lines[0];
LineTwo = myString.Lines[1];

How can I do something like that in XCode???

I need something like the Memo component in Delphi...

like image 283
Guilherme Correa Teixeira Avatar asked Sep 06 '12 00:09

Guilherme Correa Teixeira


People also ask

How do you split a string?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do I split a string into multiple strings?

split() The method split() splits a String into multiple Strings given the delimiter that separates them. The returned object is an array which contains the split Strings. We can also pass a limit to the number of elements in the returned array.

How do you split a string into characters?

Split is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters.


1 Answers

The most html strings will have (mostly invisible) newline delimiters for separating the line

NSArray *lines = [myHtmlString componentsSeparatedByString: @"\n"];
NSString *lineOne = lines[0];
...
like image 169
brainray Avatar answered Oct 10 '22 22:10

brainray