Read text from Text Editor into Array of Strings


#1

Hi

I wanted to read a text from the notepad into the array of strings. I referred to a document online where it explained how to get text from editor into file. Is there a way to get it into array instead of file?

Thanks.


#2

StringArray::addTokens() ?


#3

I tried

String abc = texteditor->getText();

But the issue is I don’t know how to convert juce::String to std::string. I need to pass the editor text into C++ function.

I will try with your suggestion.


#4

I tried using StringArray::addTokens. But it breaks the string into two and adds only one substring to the array.

E.g. CMDString = “Hi, my name is Tom. \n What are you doing? \n How are you?\n Add string to array\n”

string_array.addTokens(CMDString, “\n”, " ");

it adds “Hi, my name is Tom. What are you doing?” into the array .

Could you point out my mistake?


#5

The help for the function is pretty clear, isn’t it? You seem to be misunderstanding the last parameter.


#6

also, if you’re adding tokens separated only by newlines, addLines() might be a little easier


#7

I tried using addLines() before addTokens but same issue.


#8

Got it. Its working fine now.

Thanks for your help.