dimanche 11 novembre 2018

Find a specific kind of string in csv using vbscript

I have a question because i cannot figure out how to use the patterns in VBScript. I have csv, first line is a name, the second one will contain an "xml" so to say, that i have to search in it for a specific string. I cannot convert it to xml and search the node because the node is dynamic.

The string i am looking for is "ABC12345", it will always have the same 3 characters "ABC" at the beginning and 5 random numbers after the ABC.

So i need a script that will open up a csv, and output another csv with the first line with the name and the second will be the specific string i mentioned earlier.

So far i have found this:

Const ForReading = 1

Set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Pattern = "^[1-9]...GRP"


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)


Do Until objFile.AtEndOfStream

    strSearchString = objFile.ReadLine

    Set colMatches = objRegEx.Execute(strSearchString)

    If colMatches.Count > 0 Then

        For Each strMatch in colMatches

            Wscript.Echo strSearchString

        Next

    End If

Loop


objFile.Close

But i didn't find out how to output another csv and find the string like above.

Can somebody please help me with this?

Thank you.

Aucun commentaire:

Enregistrer un commentaire