mercredi 8 février 2017

How to list all words matching criteria from String sentence in Java

Vote count: 0

Imagine having following 'sentence' as String object:

String sentence = "AsomethingB 123 AsomethingElseB AsomethingBC abc A0B 987 ...";

How can I list everything to a String[] of words which begins with String A and ends with String B, like:

String[] words = new String[] {"AsomethingB", AsomethingElseB, "A0B"};
// note the AsomethingBC is not here.

More globally I am looking for method which will do following:

public String[] listWords(String sentence, String startSequence, String endSequence) {
  // sentence will represent String from which "extract" words
  // startSequence will represent "A" from example, may contain more characters
  // endSequence will represent "B" from example, may contain more characters
  // return type String[] will return all matches (AsomethingB...) from example
    }

Is something like this possible ?

asked 15 secs ago

Let's block ads! (Why?)



How to list all words matching criteria from String sentence in Java

Aucun commentaire:

Enregistrer un commentaire