String::readLine()?


#1

Why doesn’t this method exist? If i have a long string that has a lot of \r\n’s in it and I want to parse it line by line, i have to do the following:

std::string src = myString.toStdString();
std::istringstream f( src );
std::string l;
while( std::getline(f, l) {
    String line(l);
    //now do whatever I need to do with this individual line
    if( line.indexOf(....
}

#2

I haven’t tested, but you can probably use some string array methods :

StringArray sa;
sa.addTokens (yourString, "\n\r", "\"");

for (const String& line : sa)
{
    ....
}

edit : actually you can use StringArray::addLines() :slight_smile:


#3
auto lines = StringArray::fromLines (yourString);

#4

or…

for (auto& line : StringArray::fromLines (yourString))
    etc..