Retrieving number of lines in a textEditor component

I’m porting a wxWidgets application to juce at present and I’m trying to find the most obvious corresponding juce methods to those found in wxWidgets. Currently I’m trying to a) retrieve the number of lines in a textEditor component and b) access each line with a line index. Something along of the lines of:

for(int i=0;iNoOfLines();i++)
{
print(textEditor->GetLineText(i));
}

I’ve given up asking if things are possible in Juce, now I ask simply ask how easy it is to do in juce and if anyone can give me any suggestions?

I was able to create my own methods for doing this but they mix up std::string stuff with juce strings which I’d prefer not to do. What is the juce equivalent to std::string erase()?

int SourceDialog::GetNoOfLines()
{
std::string str = sourceEditorComponent->textEditor->getText().toUTF8();
int cnt=0;
for(int i=0;i<(int)str.length();i++)
{
int pos = str.find("\n", 0);
if(pos!=std::string::npos){
strArray.add(str2juce(str.substr(0, pos+1)));
str.erase(0, pos+1);
cnt++;
}

}
//add the very last line which won't have a "\n"...
strArray.add(str2juce(str.substr(0, 100)));
return cnt+1;

}

String myEditor::GetLine(int index)
{
return strArray[index];
}

If you need to get it into a StringArray, you could just have used StringArray::addLines()…

Thanks Jules, I hadn’t seen that method. Any suggestions on the best way to delete characters from a juce String? Something like erase() in std::string?

Looks like I missed the point of your last post: to load the string into a StringArray using addLines after which I can retrieve the numbers of elements, i.e., lines, by calling the size() method. Have it now. Cheers.