|
-
February 24th, 2000, 08:28 PM
#1
How would i read a specific line from a text file as a string?
I would like to read configuration from a text file like config.txt
each line would look like: variable value (for example: version "0.9")
What code would i need to write if i only wanted to extract one variable and it's value from the config.txt?
How would i find the variable and read it's value ????
---------------------
~:{Decayed}:~
[email protected]
http://www.q3seek.com
-
February 25th, 2000, 12:50 AM
#2
Re: How would i read a specific line from a text file as a string?
You can use a .ini file. You can use the GetPrivateProfileString or GetPrivateProfileInt API to retrieve a value of such file. To write it, you need to use the API WritePrivateProfileString/WritePrivateProfileInt. It is written to file like this:
[default]
username=cakkie
[custom]
textcolor=red
eg:
' write something to the ini file
retval = WritePrivateProfileString("default","username","cakkie","c:\myIni.ini")
' read something from the ini file
retval = GetPrivateProfileString("default","username","none",uName, 255, "c:\myIni.ini")
For more info, and a complete example, check out http://www.vbapi.com/ref/funcc.html#inifiles
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
-
February 25th, 2000, 06:21 AM
#3
Re: How would i read a specific line from a text file as a string?
If you want to include the Double quotations also then you can use INput # statement, to read one line at a time into a string buffer, not reading the ""s
Otherwise, for typical key=value pairs, WritePrivateProfilestring/int is best, as the other reply suggests
RK
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|