Escape char 和 Text Enclosure 的使用
Usage of Escape char and Text Enclosure
tFileOutputDelimited 组件中的 Escape char 和 Text Enclosure 有什么用,我们如何使用它们?
提前致谢...
要回答您的问题,请考虑 CSV 文件中的以下示例
bookId,bookname,description,authorname
1,Grammer,book that has details about grammer,author1
2,Special Characters, book that describes about some escape characters like \", punctuations and special characters ,etc.,author2
3,Mathematics, book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc, author3
我创建了一个如下所示的简单作业
在上面的示例中,字符逗号 ","
是分隔符。但是数据之间有一些逗号.
写入 CSV 文件的数据如下所示,
现在当我从那个文件中读取数据时我会得到以下数据
.------+------------------+-------------------------------------------------------+-------------------------------------.
| tLogRow_3 |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|bookId|bookName |description |author |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|1 |Grammer |book that has details about grammer |author1 |
|2 |Special Characters|book that describes about some escape characters like "| punctuations and special characters |
|3 |Mathematics |book that has mathematical operations like addition + | subtraction - |
'------+------------------+-------------------------------------------------------+-------------------------------------'
如果您注意到,"author"
列 的日志中缺少一些数据。
这是因为数据之间的逗号。为了避免这种情况,使用了 Text Enclosure
选项。 data中还有一个转义字符,即\"
。在文件中它将打印为 "
。如果 Text Enclosure
的值为 """
,那么您需要转义存在的字符 "
里面的数据。为此,您必须使用 Escape char
选项,如下所示
现在我得到的输出是
当我读取这个数据时,我会得到如下数据,
.------+------------------+-------------------------------------------------------------------------------------------------------+-------.
| tLogRow_3 |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|bookId|bookName |description |author |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|1 |Grammer |book that has details about grammer |author1|
|2 |Special Characters|book that describes about some escape characters like ", punctuations and special characters ,etc. |author2|
|3 |Mathematics |book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc.|author3|
'------+------------------+-------------------------------------------------------------------------------------------------------+-------'
如果您注意到,没有数据丢失。
希望这对您有所帮助。
tFileOutputDelimited 组件中的 Escape char 和 Text Enclosure 有什么用,我们如何使用它们?
提前致谢...
要回答您的问题,请考虑 CSV 文件中的以下示例
bookId,bookname,description,authorname
1,Grammer,book that has details about grammer,author1
2,Special Characters, book that describes about some escape characters like \", punctuations and special characters ,etc.,author2
3,Mathematics, book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc, author3
我创建了一个如下所示的简单作业
在上面的示例中,字符逗号 ","
是分隔符。但是数据之间有一些逗号.
写入 CSV 文件的数据如下所示,
现在当我从那个文件中读取数据时我会得到以下数据
.------+------------------+-------------------------------------------------------+-------------------------------------.
| tLogRow_3 |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|bookId|bookName |description |author |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|1 |Grammer |book that has details about grammer |author1 |
|2 |Special Characters|book that describes about some escape characters like "| punctuations and special characters |
|3 |Mathematics |book that has mathematical operations like addition + | subtraction - |
'------+------------------+-------------------------------------------------------+-------------------------------------'
如果您注意到,"author"
列 的日志中缺少一些数据。
这是因为数据之间的逗号。为了避免这种情况,使用了 Text Enclosure
选项。 data中还有一个转义字符,即\"
。在文件中它将打印为 "
。如果 Text Enclosure
的值为 """
,那么您需要转义存在的字符 "
里面的数据。为此,您必须使用 Escape char
选项,如下所示
现在我得到的输出是
当我读取这个数据时,我会得到如下数据,
.------+------------------+-------------------------------------------------------------------------------------------------------+-------.
| tLogRow_3 |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|bookId|bookName |description |author |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|1 |Grammer |book that has details about grammer |author1|
|2 |Special Characters|book that describes about some escape characters like ", punctuations and special characters ,etc. |author2|
|3 |Mathematics |book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc.|author3|
'------+------------------+-------------------------------------------------------------------------------------------------------+-------'
如果您注意到,没有数据丢失。
希望这对您有所帮助。