FileDocCategorySizeDatePackage
CSVRE.javaAPI DocExample1464Sat Apr 28 10:22:48 BST 2001None

CSVRE

public class CSVRE extends Object

Fields Summary
public static final String
CSV_PATTERN
The rather involved pattern used to match CSV's consists of three alternations: the first matches quoted fields, the second unquoted, the third null fields
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)


	       
	
		String line;
	
		// Construct a new Regular Expression parser.
		Debug.println("regexp", "PATTERN = " + CSV_PATTERN); // debug
		RE csv = new RE(CSV_PATTERN);

		BufferedReader is = new BufferedReader(new InputStreamReader(System.in));

		// For each line...
		while ((line = is.readLine()) != null) {
			System.out.println("line = `" + line + "'");

			// For each field
			for (int fieldNum = 0, offset = 0; csv.match(line, offset); fieldNum++) {

				// Print the field (0=null, 1=quoted, 3=unquoted).
				int n = csv.getParenCount()-1;
				if (n==0)	// null field
					System.out.println("field[" + fieldNum + "] = `'");
				else
					System.out.println("field[" + fieldNum + "] = `" + csv.getParen(n) + "'");

				// Skip what already matched.
				offset += csv.getParen(0).length();
			}
		}