Split string by delimiter

2019-04-20 18:12发布

问题:

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...

回答1:

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

NSArray *lines = [myHtmlString componentsSeparatedByString: @"\n"];
NSString *lineOne = lines[0];
...