1

有没有人编写过人员代码来读取使用分号作为分隔符和逗号作为小数分隔符的 CSV 文件?

我需要阅读使用这些字符而不是普通逗号和小数点的意大利 CSV 文件。

你的经历是什么?有什么要注意的吗?

4

2 回答 2

1

两种选择,一种使用文件布局,另一种不使用。

选项 A)使用文件布局:考虑文件布局的以下属性

  1. 定义分隔符 = “分号”
  2. 以逗号作为小数分隔符的数字字段的 FieldType = "character"
  3. 读取字段后,将逗号替换为句点并value(&new_str)在新字符串上使用以将其转换为数字

选项 B) 没有文件布局:

  1. 在您的代码中打开输入文件。
  2. 循环遍历每一行。
  3. 使用 split 来获取字段值 - 例如 &ret_arr = split(&str_line,";");
  4. &ret_arr数组将填充字段值,使用&ret_arr[1],..[2]等访问它们。
  5. 替换该数字字段中的逗号并value(&new_str)用于转换。

以上是我的经验(很长一段时间),没有其他需要注意的。希望这可以帮助!

于 2012-11-22T16:58:53.827 回答
0

If you are using a file layout it probably won't read the commas in as decimal separator although you can tell it to use the semi-colon as the separator. Your other option is to read all fields in as text and then do a replace on the number fields to replace the comma with a period and then do a value() on the string to convert it to a number.

于 2012-04-20T13:40:55.110 回答