com.claritysys.util
Class FixedWidthStringParser

java.lang.Object
  extended by com.claritysys.util.FixedWidthStringParser

public final class FixedWidthStringParser
extends java.lang.Object

A parser to break apart fixed-width records. Similar to the parse() methods of java.util.Format in that it maintains its position as you progress. Also similar to StringTokenizer, except fields are delimited by their size, not by tokens.

 FixedWidthStringParser parser = new FixedWidthStringParser (myString);
 String field1 = parser.getField (12);
 String field2 = parser.getField (4);
 parser.reset ();
 ...
 


Constructor Summary
FixedWidthStringParser(java.lang.String string)
          Create a new FixedWidthStringParser to parse the given String.
 
Method Summary
 java.lang.String getField(int size)
          Get the next field.
 int getIntField(int size)
          Get the next field as an int.
 java.lang.String getRemaining()
          Get whatever remains.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedWidthStringParser

public FixedWidthStringParser(java.lang.String string)
Create a new FixedWidthStringParser to parse the given String.

Parameters:
string - The String to parse.
Method Detail

getField

public java.lang.String getField(int size)
Get the next field.

Parameters:
size - The size of the field, in characters.
Returns:
The field.

getIntField

public int getIntField(int size)
Get the next field as an int.

Parameters:
size - The size of the field, in characters.
Returns:
Integer.parseInt(getField(size)).

getRemaining

public java.lang.String getRemaining()
Get whatever remains.

Returns:
The remaining, unparsed portion of the original String, null if no more.


Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.