5. ข้อความ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 5-1  ตัวอย่างการใช้เมท็อดของสตริง
    //..........0123456789012345678901..............
    String a = "   Java Programming   ";
    String s = a.trim();              // s = "Java Programming"
    int i = a.length() - s.length();  // i = 22 - 16
    String b = s.toUpperCase();       // b = "JAVA PROGRAMMING"
    String c = s.toLowerCase();       // c = "java programming"
    String d = a.substring(3, 7);     // d = "Java"
    int j = a.indexOf("Prog", 0);     // j = 8
    boolean e1 = "Java".equals(d);    // e1 เป็นจริง 
    boolean e2 = d.equals("Java");    // e2 เป็นจริง 
    boolean e3 = "java".equals(d);    // e3 เป็นเท็จ 
©2009 S.Prasitjutrakul