Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I am in a trouble, I have a list like below
CSS
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");

but it is not working. Please help me on this...
Note: The words may contain maximum two spaces

Thanks and regards,
Manuprasad M
Posted
Comments
Praveen Kumar Upadhyay 20-Jan-15 2:55am    
Can you mention the object that you want in your array.
Manu Prasad 20-Jan-15 3:12am    
String
BillWoodruff 20-Jan-15 6:58am    
What is an example ... from the table above ... of a word that contains two spaces ?

A very quick test here:
C#
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
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.
 
Share this answer
 
Comments
Manu Prasad 20-Jan-15 3:15am    
Hello,
I think you are correct its not TAB, they used padding while creating the list. Any other options ?
Abhinav S 20-Jan-15 3:22am    
If they are using padding with fixed number of characters, then try to split on spaces.
Manu Prasad 20-Jan-15 3:26am    
See the words itself contains spaces..
Abhinav S 20-Jan-15 4:53am    
Right. But is the space setting fixed between two words in the csv?
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.
 
Share this answer
 
Thanks all,
Its working now I used,
string[] columns = Regex.Split(line, @"\s{2,}");

-Manuprasad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900