本文整理匯總了Java中com.csvreader.CsvReader.setRecordDelimiter方法的典型用法代碼示例。如果您正苦於以下問題:Java CsvReader.setRecordDelimiter方法的具體用法?Java CsvReader.setRecordDelimiter怎麽用?Java CsvReader.setRecordDelimiter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.csvreader.CsvReader
的用法示例。
在下文中一共展示了CsvReader.setRecordDelimiter方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test137
import com.csvreader.CsvReader; //導入方法依賴的package包/類
@Test
public void test137() throws Exception {
CsvReader reader = CsvReader.parse("1;; ;1");
reader.setRecordDelimiter(';');
Assert.assertTrue(reader.getSkipEmptyRecords());
reader.setSkipEmptyRecords(false);
Assert.assertFalse(reader.getSkipEmptyRecords());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("1", reader.get(0));
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("", reader.get(0));
Assert.assertEquals(1L, reader.getCurrentRecord());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("", reader.get(0));
Assert.assertEquals(2L, reader.getCurrentRecord());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("1", reader.get(0));
Assert.assertEquals(3L, reader.getCurrentRecord());
Assert.assertFalse(reader.readRecord());
reader.close();
}
示例2: test138
import com.csvreader.CsvReader; //導入方法依賴的package包/類
@Test
public void test138() throws Exception {
CsvReader reader = CsvReader.parse("1;; ;1");
reader.setRecordDelimiter(';');
Assert.assertTrue(reader.getSkipEmptyRecords());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("1", reader.get(0));
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("", reader.get(0));
Assert.assertEquals(1L, reader.getCurrentRecord());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals(1, reader.getColumnCount());
Assert.assertEquals("1", reader.get(0));
Assert.assertEquals(2L, reader.getCurrentRecord());
Assert.assertFalse(reader.readRecord());
reader.close();
}
示例3: test39
import com.csvreader.CsvReader; //導入方法依賴的package包/類
@Test
public void test39() throws Exception {
CsvReader reader = CsvReader.parse("user_id,name\r\n1,Bruce");
Assert.assertTrue(reader.getSafetySwitch());
reader.setSafetySwitch(false);
Assert.assertFalse(reader.getSafetySwitch());
Assert.assertEquals('#', reader.getComment());
reader.setComment('!');
Assert.assertEquals('!', reader.getComment());
Assert.assertEquals(CsvReader.ESCAPE_MODE_DOUBLED, reader
.getEscapeMode());
reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
Assert.assertEquals(CsvReader.ESCAPE_MODE_BACKSLASH, reader
.getEscapeMode());
Assert.assertEquals('\0', reader.getRecordDelimiter());
reader.setRecordDelimiter(';');
Assert.assertEquals(';', reader.getRecordDelimiter());
Assert.assertEquals('\"', reader.getTextQualifier());
reader.setTextQualifier('\'');
Assert.assertEquals('\'', reader.getTextQualifier());
Assert.assertTrue(reader.getTrimWhitespace());
reader.setTrimWhitespace(false);
Assert.assertFalse(reader.getTrimWhitespace());
Assert.assertFalse(reader.getUseComments());
reader.setUseComments(true);
Assert.assertTrue(reader.getUseComments());
Assert.assertTrue(reader.getUseTextQualifier());
reader.setUseTextQualifier(false);
Assert.assertFalse(reader.getUseTextQualifier());
reader.close();
}
示例4: test46
import com.csvreader.CsvReader; //導入方法依賴的package包/類
@Test
public void test46() throws Exception {
String data = "Ch\\icane, Love on the Run, Kn\\ight R\\ider, Th\\is f\\ield conta\\ins an \\i\\, but \\it doesn't matter as \\it \\is escapedi"
+ "Samuel Barber, Adag\\io for Str\\ings, Class\\ical, Th\\is f\\ield conta\\ins a comma \\, but \\it doesn't matter as \\it \\is escaped";
CsvReader reader = CsvReader.parse(data);
reader.setUseTextQualifier(false);
reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
reader.setRecordDelimiter('i');
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("Chicane", reader.get(0));
Assert.assertEquals("Love on the Run", reader.get(1));
Assert.assertEquals("Knight Rider", reader.get(2));
Assert
.assertEquals(
"This field contains an i, but it doesn't matter as it is escaped",
reader.get(3));
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertEquals(4, reader.getColumnCount());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("Samuel Barber", reader.get(0));
Assert.assertEquals("Adagio for Strings", reader.get(1));
Assert.assertEquals("Classical", reader.get(2));
Assert
.assertEquals(
"This field contains a comma , but it doesn't matter as it is escaped",
reader.get(3));
Assert.assertEquals(1L, reader.getCurrentRecord());
Assert.assertEquals(4, reader.getColumnCount());
Assert.assertFalse(reader.readRecord());
reader.close();
}
示例5: test45
import com.csvreader.CsvReader; //導入方法依賴的package包/類
@Test
public void test45() throws Exception {
String data = "\"Chicane\", \"Love on the Run\", \"Knight Rider\", \"This field contains a comma, but it doesn't matter as the field is quoted\"i"
+ "\"Samuel Barber\", \"Adagio for Strings\", \"Classical\", \"This field contains a double quote character, \"\", but it doesn't matter as it is escaped\"";
CsvReader reader = CsvReader.parse(data);
Assert.assertTrue(reader.getCaptureRawRecord());
reader.setCaptureRawRecord(false);
Assert.assertFalse(reader.getCaptureRawRecord());
Assert.assertEquals("", reader.getRawRecord());
reader.setRecordDelimiter('i');
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("Chicane", reader.get(0));
Assert.assertEquals("Love on the Run", reader.get(1));
Assert.assertEquals("Knight Rider", reader.get(2));
Assert
.assertEquals(
"This field contains a comma, but it doesn't matter as the field is quoted",
reader.get(3));
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertEquals(4, reader.getColumnCount());
Assert.assertEquals("", reader.getRawRecord());
Assert.assertFalse(reader.getCaptureRawRecord());
reader.setCaptureRawRecord(true);
Assert.assertTrue(reader.getCaptureRawRecord());
Assert.assertTrue(reader.readRecord());
Assert
.assertEquals(
"\"Samuel Barber\", \"Adagio for Strings\", \"Classical\", \"This field contains a double quote character, \"\", but it doesn't matter as it is escaped\"",
reader.getRawRecord());
Assert.assertEquals("Samuel Barber", reader.get(0));
Assert.assertEquals("Adagio for Strings", reader.get(1));
Assert.assertEquals("Classical", reader.get(2));
Assert
.assertEquals(
"This field contains a double quote character, \", but it doesn't matter as it is escaped",
reader.get(3));
Assert.assertEquals(1L, reader.getCurrentRecord());
Assert.assertEquals(4, reader.getColumnCount());
Assert.assertFalse(reader.readRecord());
Assert.assertTrue(reader.getCaptureRawRecord());
Assert.assertEquals("", reader.getRawRecord());
reader.close();
}