|
|
||||||
|
#1
|
|
|
|
|
Hello to everybody
I would like to read a value in a txt file. For example, the value will following the egual sign. So I want to look for language and get "fr" as value. language = fr country = france Thank you by advance and have a nice day. |
|
|
|
#2
|
|
|
|
|
<bcastaing> said this in news item
news:1025 > Hello to everybody > > I would like to read a value in a txt file. For example, the value > will following the egual sign. So I want to look for language and get > "fr" as value. >> language = fr > country = france > > Thank you by advance and have a nice day. The Split function is your answer: sString = "language = fr" aString = split(sString, "=") wscript.echo trim(aString(2)) |
|
#3
|
|
|
|
|
On 8 fév, 12:27, "Pegasus [MVP]" <n> wrote:
> <bcasta> said this in news itemnews:1025 >> >> The Split function is your answer: > sString = "language = fr" > aString = split(sString, "=") > wscript.echo trim(aString(2)) Thank you very much for your quick answer. But my text file will have many lines, and I would like to find a value for each parameter I look for. For example, if I look for language, I want to get fr, If I look for country, I will have france .... Thanks |
|
#4
|
|
|
|
|
If you have it set up like an INI file
see here: http://www.jsware.net/jsware/scripts.php5#classpk In the download is a class that you can paste into your script. It will let you treat an INI file like an object. Otherwise, you can use Split to divide your file into an array of lines before proceeding. Pegasus was giving you the basic idea, but you can't expect someone to write your script for you. If you don't know how to open the file or handle arrays, etc. then you need to download the WSH help file: http://www.microsoft.com/downloads/d...C48-207D-4BE1- 8A76-1C4099D7BBB9 -- |
|
#5
|
|
|
|
|
This can get you started. strString would be the variable you charged from
either a ReadAll() or ReadLine() method. This will produce the value you are looking for but you can also tweak this to count the number of occurrences of your search term in the whole file, etc. Dim strString, strSearch, intLength strSearch = InputBox ("Enter your Search Term") If strSearch <> "" Then strString = "country = france" intLength = Len(strSearch) + 2 MsgBox RegExp(strString,strSearch) End If Function RegExp(Strng,Patrn) Dim objRegExp, Matches, Match, intCount Set objRegExp = New RegExp With objRegExp .Pattern = "\b" & Patrn & "\b.*$" .IgnoreCase = True .Global = True End With Set Matches = objRegExp.Execute(Strng) For Each Match In Matches intCount = Match.length - intLength RegExp = Right(Match.Value, intCount) Next End Function |
|
#6
|
|
|
|
|
<bcastaing> wrote in message
news:7eb3 > On 8 fév, 12:27, "Pegasus [MVP]" <n> wrote: > > Thank you very much for your quick answer. > But my text file will have many lines, and I would like to find a > value for each parameter I look for. Then, perhaps that is what you should have asked for, rather than just saying "I would like to read a value in a text file". Pegasus showed you how to do precisely that. > For example, if I look for language, I want to get fr, If I look for > country, I will have france .... What would you expect to get for the country if this text was present in the file: country = france country = germany Perhaps if you explained what the file is and what it means, it would be easier for someone to provide an answer that meets your unstated expectations. /Al |
|
#7
|
|
|
|
|
On 9 fév, 05:27, "Al Dunbar" <aland> wrote:
[..] > country = france > country = germany > > Perhaps if you explained what the file is and what it means, it would be > easier for someone to provide an answer that meets your unstated > expectations. > > /Al- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents - Hello everybody, Thanks to you I could manage my code, you are right, pegasus put me on the track with the split function. My need is to read in a text file different value that will be used to configure an application the txt file will look country = france language = fr info1 = value ..... So now with the split function I can put all the string in an array and look for the wanted value. Set objFile = objFSO.OpenTextFile("\\c:\script\param.txt", ForReading) strContents = objFile.ReadAll objFile.Close arrWords = Split(strContents, vbcrlf) intStart = 0 IntFindLine = 0 For Each strWord in arrWords If InStr(strWord, value) Then intStart = intStart + 1 End If If intStart > 0 Then intFindLine = IntFindLine + 1 strLine = strLine & strWord if intFindLine > 0 then exit For End If Next arrWords = Split(strLine, " = ") strValue = (arrWords(1)) Wscript.Echo strValue |
|
|
| Similar Threads | |
| MSXML4 (Document Object Model XML), read the file, read thevariables, fill it, send over socket Hello together, I would like to make the following. - <root> - <header eventId="" version="" eventName="" timeStamp=""> <location lineNumber="" stationNumber=""... |
|
| How to read from a file, stored the data in an array, and return number of records read back to main I am taking a C++ class in college and having problems completing last week's homework. Any help is greatly appreciated. The program is to read from a filing containing... |
|
| Database file and folder are not read only but error message says it is read only?? This is on a remote server. Everything works in the development envirmonment. Any ideas? Thanks, Keith Failed to update database "C:\BTM_ROOT\APP_DATA\ASPNETDB.MDF"... |
|
| DataInputStream Read Method -- Is Offset From Start of File or Last Read? If I have a DataInputStream (called dis) wrapped around a FileInputStream, when I do this: dis.read(byteInput, 0, intLength); if intLength is set to the entire length of... |
|
| File system get auto change from read-write to read-oly I have a very strange file system with OS Redhat 7.2 The file system is read-write, but some how it randomly changes to read-only at any time. Suddenly all users can write... |
|
|
All times are GMT. The time now is 05:47 AM. | Privacy Policy
|