<zerbie45@xxxxxx> wrote in message
> hi guys,
> I have a text file which I need to read from a vbscript, but I should
> only get the last string. does anybody has an example that I could use
> to write such script ?
> further, the file has two empty strings at the bottom. which is the
> best method to deal with this ? should the script read the third line
> from the bottom, or is it simpler to get rid of these empty strings ?
> an example would be very, very appreciated!
If I am understanding your request, I think something like this should
work for you:
Dim oFSO, oRegEx, sFileName, sText, oMatches
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.Multiline = True
oRegEx.Global = True
sFileName = "C:\MyFile.txt"
sText = oFSO.OpenTextFile(sFileName, 1).ReadAll
oRegEx.Pattern = "^([^\s]+)$"
Set oMatches = oRegEx.Execute(sText)
MsgBox oMatches(oMatches.Count - 1)