Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

[PLAIN][sOLVED]: how to detect tab symbol in text..[/PLAIN]

 

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

Edited by mccbala
Posted

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

My Development System

Intel Core i7 920 @2.66Ghz

6 GB DDR3 SDRAM

Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot

GeForce GTX295 1.8 GB

3.5 TB HD

Posted

[PLAIN][sOLVED]: how to detect tab symbol in text..[/PLAIN]

 

SOLVED:

                   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))

Posted

[PLAIN]Re: [sOLVED]: how to detect tab symbol in text..[/PLAIN]

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...