1 25 26 package net.killingar; 27 28 import java.util.StringTokenizer ; 29 30 class DelimitedString 31 { 32 public static final int END = -1; 33 34 private String segments[] = null; 35 private String padding[] = null; 36 37 public DelimitedString(String source) 38 { 39 StringTokenizer st = new StringTokenizer (source, " \t\n\r\f", false); 40 41 segments = new String [st.countTokens()]; 42 padding = new String [segments.length]; 43 44 int i = 0; 45 while(st.hasMoreTokens()) 46 { 47 segments[i] = st.nextToken(); 48 51 54 i++; 55 } 56 } 57 58 public String getSegment(int i) 59 { 60 if(i < segments.length) return segments[i]; 61 else return null; 62 } 63 64 public String getSegmentsBetween(int start, int end) 65 { 66 StringBuffer sb = new StringBuffer (); 67 68 if(end == END) 69 end = segments.length; 70 71 for(int i = start;i < end; i++) 72 { 73 if(i > start) sb.append(" "); 74 sb.append(segments[i]); 75 } 76 77 return sb.toString(); 78 } 79 } | Popular Tags |