previous | start | next

String Example

public class StringEx {

  /**
   * @param args
   */
  public static void main(String[] args) {
    String date = "04/09/2013";

    int startpos = 0;
    int endpos = date.indexOf("/");
    String monthStr = date.substring(startpos, endpos);

    startpos = endpos + 1;
    endpos = date.indexOf("/", startpos);
    String dayStr = date.substring(startpos, endpos);

    startpos = endpos + 1;              
    String yearStr = date.substring(startpos);

    System.out.printf("m = %s, d = %s, y = %s\n", monthStr, dayStr, yearStr);

  }

}

Output:

m = 04, d = 09, y = 2013
      


previous | start | next