文本到多列 [英] Text to multiple columns
问题描述
嗨朋友们,
我遇到了麻烦,我有一个如下列表
Hi friends,
I am in a trouble, I have a list like below
1181 1003 /LW2A 1 W14X68 A992 16'-3 1/2" id:7959532
1182 1000 /LW1A 1 W12X53 A992 16'-3 1/2" id:8085877
1182 1008 /LW5A 1 W12X53 A992 16'-3 1/2" id:8085856
1183 1005 /LW3A 1 W30X90 A992 16'-3 1/2" id:7957895
1184 1005 /LW3A 1 W24X94 A992 16'-3 1/2" id:7958098
1184 1008 /LW5A 1 W24X94 A992 16'-3 1/2" id:7957812
1184 1008 /LW5A 1 W24X94 A992 16'-3 1/2" id:7957913
1184 1008 /LW5A 1 W24X94 A992 16'-3 1/2" id:7958116
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:3434205
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:3434226
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:3434240
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:3434247
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:4061137
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:4061152
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:4061434
1185 1001 /LW1B 1 W16X77 A992 14'-5 1/4" id:4063687
1186 1001 /LW1B 1 W16X89 A992 29'-10 15/16" id:3434142
我想要在任何选项卡即将到来的地方分割每一行,我使用
I want to split each lines wherever tab is coming ,I used
string[] columns = Regex.Split(line, @"\t");
但它不起作用。请帮帮我...
注意:单词可能包含最多两个空格
谢谢和问候,
Manuprasad M
but it is not working. Please help me on this...
Note: The words may contain maximum two spaces
Thanks and regards,
Manuprasad M
推荐答案
这里的一个非常快速的测试:
A very quick test here:
string test = "9199\t6345\t2421\tAC62\t14BX\tCNY0";
string[] columns = Regex.Split(test, @"\t");
foreach (string s in columns)
{
Debug.WriteLine(s);
}
说正则表达式正确地打破了字符串:
Says that the regex breaks the string correctly:
9199
6345
2421
AC62
14BX
CNY0
所以我建议这是一个数据问题:检查列是否用TAB字符分隔(使用十六进制编辑器 - PSPad [ ^ ]是我使用的,它有一个十六进制模式),如果是,显示使用输入是什么,输出是什么,以及你期望的输出。
So I suggest that it's a data problem: check that the columns are separated by TAB characters (use a Hex Editor - PSPad[^] is what I use and it has a Hex mode) and if it is, show use exactly what the input is, the output is, and what you expect the output to be.
那里可以是多个标签,例如\ t \\\。
或者他们可以使用填充或空格以及标签。
试着找出用于分隔数据的确切字符集。
There could be multiple tabs e.g. \t\t.
Or they could be using padding or blank spaces along with the tab.
Try to find out the exact character set that separates data.
全部谢谢,
我现在正在使用它,
Thanks all,
Its working now I used,
string[] columns = Regex.Split(line, @"\s{2,}");
-Manuprasad
-Manuprasad
这篇关于文本到多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!