About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter
About streamreader & streamwriter About streamreader & streamwriter
About streamreader & streamwriter
Go Back  Xtreme Visual Basic Talk > > > About streamreader & streamwriter


Reply
 
Thread Tools Display Modes
  #1  
Old 04-25-2005, 03:20 AM
tomij tomij is offline
Newcomer
 
Join Date: Apr 2005
Location: Slovenija
Posts: 15
Unhappy About streamreader & streamwriter


When i read a text file i want to use only part of line.

TestFile.txt
Voltage1 : 5V " input voltage A0"
Voltage2 : 5,5 " input voltage A1"
Voltage3 . 0,96 " output voltage PIN 6"
...


I cannot use ReadLine(). But output from Read() is integer.
For example:


Dim sr As StreamReader = New StreamReader("C:\TestFile.txt")
Dim strdata1 As String

strdata1 = sr.Read()

if strdata = "Voltage1 : 5V " input voltage A0"" then
MessageBox.show("Voltage1 : 5V")
end if


What can i do?
Reply With Quote
  #2  
Old 04-25-2005, 04:16 AM
Ruffnekk's Avatar
Ruffnekk Ruffnekk is offline
Centurion
 
Join Date: Mar 2005
Location: Rotterdam, Netherlands
Posts: 167
Default

If every line of the textfile is in the same format, you can use ReadLine to get the next line and then split the line at the " character in your case. For example:

Code:
Dim strTemp As String dim arrTemp() As String strTemp = tReader.ReadLine() arrTemp = strTemp.Split(Chr(34)) MsgBox(arrTemp(0))

What this code does, is read the next line, then split that string at the double quotation character (chr(34)) and then output the first element to the messagebox.

If, for example, the read line was: Voltage1 : 5V " input voltage A0", then the first element of the array (0) will contain: "Voltage1 : 5V "
__________________
Objection, your honor!
Who decides who's crazy?
http://www.freewebs.com/ruffnekk

Firefox Rox!
Reply With Quote
  #3  
Old 04-25-2005, 11:40 PM
tomij tomij is offline
Newcomer
 
Join Date: Apr 2005
Location: Slovenija
Posts: 15
Default

Thanks Ruffnekk

It work perfectly, but how is it with:

-- 22025.1.0 = STRING: "Voltage and Current for Amplifier"
-- 22025.1.1.0 = STRING: "Voltage Amplifier"
-- 22025.1.2.0 = STRING: "Current Amplifier"

-- 22025.3.0 = STRING: "Current Preamp"

if i want only 22025.1.1.0 but not the = STRING: "Voltage Amplifier"
Reply With Quote
  #4  
Old 04-26-2005, 12:05 AM
tomij tomij is offline
Newcomer
 
Join Date: Apr 2005
Location: Slovenija
Posts: 15
Default

I found out how i can do that.

Thanks Ruffnekk
Reply With Quote
  #5  
Old 04-26-2005, 03:01 AM
Ruffnekk's Avatar
Ruffnekk Ruffnekk is offline
Centurion
 
Join Date: Mar 2005
Location: Rotterdam, Netherlands
Posts: 167
Default

You just have to find a character that separates what you want from the rest. In the last case, you could split the string at the = sign.
__________________
Objection, your honor!
Who decides who's crazy?
http://www.freewebs.com/ruffnekk

Firefox Rox!
Reply With Quote
  #6  
Old 04-27-2005, 02:46 PM
tomij tomij is offline
Newcomer
 
Join Date: Apr 2005
Location: Slovenija
Posts: 15
Talking

Hello

I have a problem again.I found a part of text in my output file:

Used for PIN1 (IC1-5)

The problem is that i need to read if this line contain PIN1 and (IC1-5).
If line contains PIN1 and (IC1-5) then msgbox("Use this part of file") else
msgbox("Don't use this part of file").
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter About streamreader & streamwriter
About streamreader & streamwriter
About streamreader & streamwriter
 
About streamreader & streamwriter
About streamreader & streamwriter
 
-->