how to detect tab symbol in text..

mccbala

Newcomer
Joined
May 7, 2009
Messages
5
Location
Singaara Chennai!
[SOLVED]: how to detect tab symbol in text..

Hi..

I use stream reader to input lines from a text file to a listbox.. While inputting, i want to detect the tab characters in it. Like After the second tab character, extra text should be ignored. How can i do this? Plz reply ASAP.. I just need the part of code which detects and ignores the extra text. Plz don't take pains to write the whole coding.. ;)

Thanks

mccbala
 
Last edited:
Hi

StreamReader sra = new StreamReader ("c:\\File.txt");
string aLine = sra.ReadLine();
Console.WriteLine(aLine);
string[] TokenBuffer = aLine.Split('\t');

where \t comes from http://msdn.microsoft.com/en-us/library/h21280bw.aspx

TokenBuffer[0] & TokenBuffer[1] indicates the string before the second tab while the other entries in this array are extra text
Loop through it for each line and your done ;)

~ DP

srry couldn't help myself write a little bit of code :p
 
[SOLVED]: how to detect tab symbol in text..

SOLVED:
Code:
                    line = line.Trim()
                    arr = line.Split(ControlChars.Tab)
                    If Not ListBox1.Items.Contains(line) And arr.Length > 2 Then ListBox1.Items.Add(arr(0) & " - " & arr(1))
 
Re: [SOLVED]: how to detect tab symbol in text..

declare arr() as String before you use the code.. A small note for anyone who uses this code.. Please don't copy paste the code. Understand it and then use it. :)

mccbala
 
Back
Top