English 中文(简体)
我如何发现用户的所在地,以获得正确的茨夫分离器?
原标题:How do I detect the user s locale to get the correct csv separator?

我有一个简单的数据转换工具,它能够产生的一项产出是一纸空文。

This works perfectly here in the UK but when I shipped it out to a German customer I had some issues. Specifally, they use a , to represent the decimal point in a floating point number and vice versa. This means that when they open their data file in excel, the result is rather messy to say the least :-)

替代正确的特性是轻而易举的,但我如何能够发现是否适用?

<><>Edit>:

因此:

a,b,c
1.1,1.2,1.3
"1.1",1,2,"1,3"
"this,is,multi-
-line",this should be column 2, row 4
a;b;c
"a;b","c"

..looks like this when loaded into excel in the UK:

+----------------+-----+-----+-----+
| a              | b   | c   |     |
+----------------+-----+-----+-----+
| 1.1            | 1.2 | 1.3 |     |
+----------------+-----+-----+-----+
| 1.1            | 1   | 2   | 1,3 |
+----------------+-----+-----+-----+
| this,is,multi- |     |     |     |
| -line          | 2   | 4   |     |
+----------------+-----+-----+-----+
| a;b;c          |     |     |     |
+----------------+-----+-----+-----+
| a;b            | c   |     |     |
+----------------+-----+-----+-----+

而德国的情况如何?

问题回答

使用:

System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator

CSV: The “List separateor” string be used as the delimiters in CSV (see below on how to change this changing). “List separateor”的价值在作为CSV储蓄时也反映在Excel。

阅读CSV:在CSV确定定义是另一个例子,更为复杂。 原则上,可以使用一种“,”作为某个制度中的CSV delimiter,并使用一种“;”或甚至一种“*”或任何(“指示”)作为另一个系统的限定者: 本条就如何在阅读跨系统CSV档案时发现CSV的划界人员提供了一些见解:

http://www.codeproject.com/Articles/231582/Auto-detect-CSV-separator

也可以通过将Windows的“List separateor”价值改为如下(每个WindowsOS不同):

  • Open Region and Language dialog.
  • Select on the "Format" tab.
  • Click on "Additional Settings"
  • Edit the value of the "List separator"

其他人已经提到,一般而言,应当使用混合体,并且应当双重引用田地。 然而,还有一些特殊行为,导致正确的CSV档案被错误地进口。 这是因为,按违约计算,MS Excel采用在区域和语言选择的Windows系统设置的分离器清单。 就美国/联合王国而言,它只是 com,但就德语这样的语言而言,它只是半殖民地。 因此,就MS Excel而言,选择是使用不同地方的分离器。

货币兑换率() 据说CSV分离器并不依赖文化。 它是CSV档案中的一份财产,你向教区表示。 谈到教区,我真诚地希望你能够。 不推出自己的CSV教区

As others recommended already, the format should not be locale sensitive. This is true for storage (in files like CSV or other formats) or communication protocols. You should worry about locale sensitivity for the presentation layer only. Otherwise it means that a file saved by an American user (for instance) cannot be loaded by a German one (and the other way around).

http://mihai-nita.net/2005/10/25/data-internationalization/“rel=“nofollow”http://mihai-nita.net/2005/10/25/data-internationalization/。

我对该问题的解读方式是,问题不是在案卷上。 对所有用户来说,如上文所有答复所重复的,可能采用相同的格式。

然而,Excel VBA的申请是当地敏感的。

当Excel由不同国家的不同用户开放时,他们正在利用现有的区域环境,有时不同于.csv文档,因此以不同的方式在.csv文档中解释数据。

因此,问题确实是,我们如何围绕它进行规划,以便我们的法典能够摘取目前的区域分裂者,然后进行正确的解释?

一种方式是,使一部小的法典能够把一小数写到试验室,然后读到底什么是用的,但应该有更根本的方法去做。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签