Suggestions from the IDE / how to do?

Asked

Viewed 90 times

1

I have the following problem

I have some text that will be inserted by the user and we will take as an example

Inserted sentence: I wish I knew how to program better #today.

I wanted a listview to appear below these words ( ex: #today ) when I looped words started by # and these were replaced by suggestions in this listview ?

How do I do it? Thanks from now on.

  • 1

    What should appear in listviews? And replace it with exactly what word? You can give examples of the expected result for the example you gave in the question?

1 answer

2

By using the tag I believe your difficulty is changing the #nome of string, in your case I believe this solves:

foobar.replaceAll("(^|\\s)#hoje($|\\s)", "$1" + valorAtual + "$2");

Note: I tested it \\b in place of (^|\\s) and ($|\\s), but I don’t know why it had no effect.

In a simple example would look something like:

final String frasePadrao = "Eu gostaria de saber programar melhor #hoje";
final String fraseRegex = "(^|\\s)#hoje($|\\s)";

listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>()
{
    @Override
    public void changed(ObservableValue<? extends String> observable, String valorAntigo, String valorAtual)
    {
        minhaLabel.setText(
           frasePadrao.replaceAll(fraseRegex, "$1" + valorAtual + "$2")
        );
    }
});

minhaLabel would be a label where the text appears


Explaining the regex

  • (^|\\s) search a space or start of the string
  • #hoje search the word I would like to be replaced
  • ($|\\s) search space or string ending

I mean, that way you can write the #hoje at any position of the string, avoiding conflict with other texts that could vary. Technically the \\b should solve this of the spaces between the word, but I don’t know if it’s a Java behavior, it just doesn’t work:

 "\\b#hoje\\b"

In other languages I had no problem using the \b. However the (^|\\s) and ($|\\s) already answer to that

  • Thank you!!!!!!!!

  • For nothing @Hfleury please, if this answer solved your problem could mark it as correct? I would be very grateful, if you do not know how to do see this tutorial (it is fast): https://pt.meta.stackoverflow.com/q/1078/3635

Browser other questions tagged

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