find First Word Index - Android java.lang

Android examples for java.lang:String Search

Description

find First Word Index

Demo Code

public class Main {
  public static final String WHITESPACE = "\\s+";

  public static int findFirstWordIndex(CharSequence sentence) {
    for (int i = 0; i < sentence.length(); i++) {
      if (!String.valueOf(sentence.charAt(i)).matches(WHITESPACE)) {
        return i;
      }/*from  w  ww  .jav  a 2  s. com*/
    }
    return 0;
  }

}

Related Tutorials