|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.cweiske.tools.CSVReader
a small CSV (comma separated values) reader parses a given string into an array of strings It is aware of: - separators inside field values - quotes inside of quoted field values - multiline field values It should be very small, but have the most needed/used features of CSV files It has not been designed to be fast or extreme memory-efficient. The following things may give you problems: - It doesn't care about encodings - It doesn't know single quotes for encapsulating field values - Wants to have a string passed. So for large files, it consumes really much memory The following pages were helpful when writing the class: - http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm - http://www.ricebridge.com/products/csvman/formats.htm
Constructor Summary | |
CSVReader()
simple constructor |
|
CSVReader(java.lang.String strData)
constructor with CSV data as parameter |
|
CSVReader(java.lang.String strData,
char chSeparator)
constructor with CSV data and separator as parameter |
|
CSVReader(java.lang.String strData,
char chSeparator,
boolean bAcceptEscapes)
constructor with CSV data, separator and escape switch as parameter |
Method Summary | |
static int |
countOccurences(java.lang.String strData,
java.lang.String strSearch)
counts the number of occurences of strSearch in the strData string |
boolean |
getAcceptEscapes()
|
char |
getChar(int nPos)
just get a single char from the string |
java.lang.String |
getData()
|
char |
getSeparator()
|
char |
guessSeparator()
tries to guess the separator char by analyzing the CSV data |
java.lang.String[][] |
parseData()
same as parseData(0) |
java.lang.String[][] |
parseData(int nLines)
parses the string and returns the CSV data in a two-dimensional string array |
void |
setAcceptEscapes(boolean bAcceptEscapes)
if chars like '\"' and '\r' or '\n' shall be threat as quote, carriage return and newline (normally, they are threat as two chars and quotes are quoted as double-quotes) |
void |
setData(java.lang.String strData)
set the file contents (CSV data) which can be parsed then |
void |
setSeparator(char chSeparator)
sets the separator char. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CSVReader()
public CSVReader(java.lang.String strData)
public CSVReader(java.lang.String strData, char chSeparator)
public CSVReader(java.lang.String strData, char chSeparator, boolean bAcceptEscapes)
Method Detail |
public void setData(java.lang.String strData)
public java.lang.String getData()
public void setSeparator(char chSeparator)
public char getSeparator()
public void setAcceptEscapes(boolean bAcceptEscapes)
public boolean getAcceptEscapes()
public char guessSeparator()
public java.lang.String[][] parseData()
public java.lang.String[][] parseData(int nLines)
nLines
- How many lines shall be parsed (0 for all)public char getChar(int nPos)
public static int countOccurences(java.lang.String strData, java.lang.String strSearch)
strData
- The string which shall be searchedstrSearch
- The search string
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |