mccbala Posted May 7, 2009 Posted May 7, 2009 (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 May 8, 2009 by mccbala Quote
DPrometheus Posted May 8, 2009 Posted May 8, 2009 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 Quote 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
mccbala Posted May 8, 2009 Author Posted May 8, 2009 tks man.. this is in c.. lemme see if the same works in vb .net do i need the code.. Quote
mccbala Posted May 8, 2009 Author Posted May 8, 2009 it doesn't work man.. actually.. i dunno how to specify the tab character in vb split.. i tried this.. but no results.. Quote
mccbala Posted May 8, 2009 Author Posted May 8, 2009 [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)) Quote
mccbala Posted May 8, 2009 Author Posted May 8, 2009 [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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.