Okay, I was wondering if there is a way to read and set a variable based on a certain line in a text file
IE
I have a configuration file that has a product key. The product key is the fifth line in the configuration file. How do I read just the product key?
Read particular line in txt document
Started by Danerd100, May 29 2008 07:16 AM
5 replies to this topic
#1
Posted 29 May 2008 - 07:16 AM
|
|
|
#3
Posted 29 May 2008 - 11:42 AM
I am using kbasic start [KBasic]
It uses the same syntax as VB, and i believe it is xml compatible. Could u show me how in .NET?
It uses the same syntax as VB, and i believe it is xml compatible. Could u show me how in .NET?
#4
Posted 29 May 2008 - 11:45 AM
Use the System.Xml namespace. Say you have a structure such as this in your file:
[highlight=xml]
<?xml version="1.0">
<config>
<productkey>149JJF9349</productkey>
<othersetting>value</othersetting>
</config>
[/highlight]
Like that. Then, in code:
[highlight=vb]
Dim doc As New System.Xml.XmlDocument()
doc.Load(IO.File.ReadAllText("C:\temp\config.xml"))
Dim ProductKey As String = doc.SelectSingleNode("config/productkey").InnerText.ToString()
[/highlight]
See?
[highlight=xml]
<?xml version="1.0">
<config>
<productkey>149JJF9349</productkey>
<othersetting>value</othersetting>
</config>
[/highlight]
Like that. Then, in code:
[highlight=vb]
Dim doc As New System.Xml.XmlDocument()
doc.Load(IO.File.ReadAllText("C:\temp\config.xml"))
Dim ProductKey As String = doc.SelectSingleNode("config/productkey").InnerText.ToString()
[/highlight]
See?
Edited by Xav, 29 May 2008 - 11:48 AM.
#5
Posted 29 May 2008 - 12:09 PM
In Visual Basic 6.0 you can use the InStr function.


Sign In
Create Account


Back to top









