Difference between revisions of "Substring"

From Progzoo
Jump to navigation Jump to search
 
Line 42: Line 42:
 
   public static void main(String[] argv)
 
   public static void main(String[] argv)
 
                         throws Exception{
 
                         throws Exception{
    System.out.printf("%-20s%-20s\n\n","s","s.substring(5)");
 
 
     for (String s: "One two three\nfour five six".split("\n"))
 
     for (String s: "One two three\nfour five six".split("\n"))
 
       System.out.printf("%-20s%-20s\n",s,Q(Qs.substring(5)Q)Q);
 
       System.out.printf("%-20s%-20s\n",s,Q(Qs.substring(5)Q)Q);

Latest revision as of 21:42, 8 May 2008

Use substring(a,b) to get part of a string.

substring(5,7) extracts characters form position 5 to just before position 7.

0 1 2 3 4 5 6 7 8 9 10 11 12
O n e t w o t h r e e
f o u r f i v e s i x



[Font] [Default] [Show] [Resize] [History] [Profile]

Use substring(a) to get part of a string.

substring(5) extracts characters form position 5 to the end.

0 1 2 3 4 5 6 7 8 9 10 11 12
O n e t w o t h r e e
f o u r f i v e s i x



[Font] [Default] [Show] [Resize] [History] [Profile]