How to replace the space character with another one?

Asked

Viewed 590 times

5

The title of the question is to understand that it is simple I ask silly ,but I would not like to know how to replace the space of a EditText by something else ,as in the image below: imagem representando os espaço

In the case of the image the spaces are replaced by gray dots that are before the declarations of the Javascript variables. If copy one of the balls and paste into another EditText ,that is not the one of the editor ,the ball becomes a space.

  • Replace where? In Android Studio editor?

  • No ,I’m making a code editor, in it I want to make the replacement.

  • Use the method addTextChangedListener . So you can change the text after changes to it.

  • Not that way ,in the image editor ,if you copy a ball of those and go in another editor the copied ball becomes a space.

  • Put the problem-relevant code in the question. How is it to save/show what code appears in the editor?

  • The focus of the question has nothing to do with the code of the image and yes we spaces that in this specific application are balls ,but if copy one of the balls and paste in another application the ball becomes a space.

  • So what is specifically your question ? How to transform a space of a String on a ball ? Any character replacement can be done with replace. I haven’t been to see but it certainly has Unicode characters that resemble balls

  • I think I have the answer to the question ,I’m not sure but I think it may be the source of the image editor.

  • These "balls" do not actually exist, they are only space, the editor displays so to make it easier to read, so when copying, only spaces come

  • Is a configuration of the editor

  • This is an Android application not Pc. And I know that the balls do not exist if I did not know would not have come to the conclusion that are spaces.

  • I think I get it, you want it to appear like that in the editor, and when copying, don’t go like . but spaces. That’s it?

  • Yes ,the Android application that has this function is called Es File Explorer in Note Editor ,in this editor the tab is also changed but instead a ball is a bar.

Show 8 more comments

1 answer

1

First of all you will need to do a validation. Note that gray dots commonly appear only to the left of the code, not to the right or between the code. You will also need to work on visual formatting. Here is a sample of how the basic logic will work:

EditText textBox = (EditText) findViewById(R.id.textBox);
textBox.addTextChangedListener(new TextWatcher() {

    public void afterTextChanged(Editable s) { }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if(s.contains(" ")){
            s.replace(" ", ".");
        }
        myOutputBox.setText(s);
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.