Tab Split String Now Working.

Started by
3 comments, last by larsbutler 11 years, 8 months ago
Tab Split String Now Working.

Please Help. I wrote a C# program that reads code one line at a time. Each line has data seperated by tabs.

Here is what my C# code is supposed to do. The line is supposed to be split into a string array by using the "Split" string methodIt is supposed to be spit read in text one line at a time and I use the "Split" method to group the line according to the tab character.

But, as this screen shot shows, it does not work. Any idea why?

problem.png
Advertisement
Are you sure that the input text has tabs? How was the input text constructed?

Are you sure that the input text has tabs? How was the input text constructed?

How wierd. It looks like a text editor replaced the tabs with spaces without my say-so.
Depending on the text editor used some have an option to replace tabs with spaces; check to see if that option is selected.
If you want a more bullet-proof way to handle this (in case the spacing is a tab, 4 spaces, 8 spaces, 3 spaces, 1 space, whatever), you could instead do a regular expression split on whitespace.

I'm not a C# guy, but this looks like something you could use:
http://msdn.microsoft.com/en-us/library/8yttk7sy.aspx
For info about regex (in .NET context):
http://msdn.microsoft.com/en-us/library/hs600312.aspx

Hope that helps.

This topic is closed to new replies.

Advertisement