Save textArea with ControlP5

Hello guys,

How could I save the contents of a textArea in a text file?

It worked to open normal as the example in the link below, but still managed to save not ... tried this code, but it gives error, the syntax is wrong ...

https://forum.processing.org/one/topic/textarea-using-controlp5.html

stretch code:

//String[] lines = loadStrings(textArea.getText());
//printArray(lines);

String lines = textArea.getText()
println(lines);

for (int i = 0; i <= lines.length-1; i++){
   lineSave[i] = lines[i];
}

saveStrings(split(lineSave, "\n"));

Thanks in advance for your attention.

Answers

  • Another detail, it would be possible to select text the textArea to copy and paste?

    Thank you

  • Have you tried something like: saveStrings( split(textArea.getText(), ENTER) ); :-/

  • Hello GoToLoop, thank you for the return ...

    Gave an error when I tried to run, it seems that does not support directly this way ... you tell if there was a way to convert textArea to an Array String?

    It seems that to accept need to be this way ...

    Grateful for the attentionErro01

  • Your error is telling you what is wrong. Please check the reference to see how to use the saveStrings function:

    https://processing.org/reference/saveStrings_.html

    Kf

  • kfrajer hello, thanks for the tip ...

    The problem is that I am trying to record a Textarea (with ControlP5) in this case would need a line-end path (one Enter for example), so it would be in the form of sentence ...

    I need to know how to verify that the text has the "enter" as path ...

    comma works but how to identify the enter?

    //String words = "Phrase text test 1, Phrase text test 2, Sentence test text 3";
    String words = "Phrase text test 1 \n Phrase text test 2 \n Sentence test text 3";
    String[] list = split(words, ',');
    
    // Writes the strings to a file, each on a separate line
    saveStrings("nouns.txt", list);
    

    In Textarea, I see the text in this way:

    Phrase text test 1 Phrase text test 2 Sentence test text 3

    How could I convert the text of Textarea ( ControlP5) to String Array?

    Thank you very much

  • Sorry the text should look like this in TextArea:

    Phrase text test 1 
    Phrase text test 2 
    Sentence test text 3
    

    Thank you

  • edited June 2016 Answer ✓

    Sorry I had not looked up saveStrings()'s reference before posting.
    I've just copied and pasted @Jose_Aparecido's line and modified it a little. X_X
    Of course, both the original and the tweaked 1 lacked the filename 1st parameter: b-(

    saveStrings( dataPath("text_area.txt"), split(textArea.getText(), ENTER) );
    
  • Hello GotoLoop,

    It worked perfectly, thank you! :)

Sign In or Register to comment.