Search code examples
androidandroid-edittexttextviewandroid-textattributes

Find End of line (/n) in EditText android


I have a edittext, i want to append some characters before text on each line of the edit text depending upon the button pressed. for example

if( fivespacesbutton is pressed )
then
append five spaces on each line the function OnClick(View v) has called.

I think if i get to know about end of line (/n) then i will append five spaces before each line.

any idea how can i get /n from

EditText scene=(EditText)findViewById(R.id.editText11);

Solution

  • String text = scene.getText().toString();
    String result = "";
    for (String line : text.split("\n"))
    {
       result += "    " + line + "\n";
    }
    scene.setText(result);