![]() |
How to parse a string from a txt file?
Hi there, I'm on my second day of scripting with NSIS and have a need to be able to ready in a value from a text file.
The file format is as follows: PHP Code:
Also, hope I'm not clouding the issue here but, does FileOpen accept relative paths? Any help is much appreciated. Thanks, Andy |
ConfigRead
I would refrain from using relative paths in NSIS scripts in case you change the working directory with SetOutPath. Stu |
The easiest method might be using the INI functions:
Given the following file: You can read the info like this:code: code: |
He didn't include a section header in his snippet in which case ReadINIStr would not work.
Stu |
In fact as you have rightly said ConfigRead won't work here either due to the padding. You will have to use FileRead in a loop with some string manipulation in there to find and chop the bit you want.
Stu |
Or add one single line (section header) to file ;)
|
1 Attachment(s)
This might help. It uses ConfigRead and WordReplace, both of which are in NSIS help. See the attachment for complete example.
code: |
That will work assuming there are no entries like ProductNameXYZ = thus reading the wrong value.
Stu |
Parsing using biterscripting when name=value pairs have flexible syntax
Excellent help so far.
Winamp is great. Occasionally I tend to use biterscripting (.com for free download) for simplified parsing. The following code in biterscripting will get you the values from the file in the flexible syntax you specified. # START CODE var str input, line ; cat <file> $input while ($input <> "") do lex -e "1" $input > $line wex "[3" $line done # END CODE You may want to put this code in a file to create a script, and pass the input file name ($file) as input argument to that script. The lex command (line extractor), extracts each line. The wex command (word extractor), extracts [3, that is everything after (and including) the third word on that line. The wex command takes care of variable sytaxes such as name=value, name = value, name \t=value, etc. The system variable $wsep (word separator) specifies what are considered word separators. Hope this helps. Sen |
| All times are GMT. The time now is 04:27. |
Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.