Jump to content

Split a multi line string into separate variables


blemas
 Share

Recommended Posts

The McAfee return for AV defs per "C:\Progra~1\Common~1\McAfee\SystemCore\csscan.exe -Versions" is ...

CommonShell Command Line Scanner Lite (VSCORE.15.5.0.3960)

    Engine version: 5800.7501

    DAT version:    8450.0

    Time required:  15 milliseconds

I want to isolate the actual DAT version as "8450.0".  There may be an easier way to get the DAT Version via other McAfee or registry methods but essentially I just want to know how to parse a string at a character or @CRLF into two separate strings for further parsing. Example:

$string = "Name=Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"

Parse into $var1 = "Name" & $var2 = "Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"

From there I'd like to parse $var2 at "|" into  $var3 = "Microsoft Windows 10 Professional" and $var4 "C:\windows|\Device\Harddisk0\Partition2"

 

 

 

 

 

Link to comment
Share on other sites

Welcom to AutoIt and the forum!

Use something like this:

$string = "Name=Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
$aResult1 = StringSplit($string, "=")
$aResult2 = StringSplit($aResult1[2], "|")

You get two arrays with the resulting substrings.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks for the help. That looks like it would work but I'm getting no results (pebkac?).

$string = "Name=Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
$aResult1 = StringSplit($string, "=")
$aResult2 = StringSplit($aResult1[2], "|")
MsgBox(0, "aResult1", "" & $aResult1, 1.5)
MsgBox(0, "aResult2", "" & $aResult2, 1.5)

What am I missing?

 

Link to comment
Share on other sites

  • Moderators

Moved to General Help and Support, as the Examples forum clearly states:

Quote

Do not post general support questions here, instead use the AutoIt Help and Support forums.

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Got it...

#include <Constants.au3>

Global $DOS, $Message = '' ;; added "= ''" for show only.

$DOS = Run(@ComSpec & " /c C:\Progra~1\Common~1\McAfee\SystemCore\csscan.exe -Versions", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$local_av_version = StdoutRead($DOS)

MsgBox(65536, "", "The McAfee AV information" & @CRLF & $local_av_version)

Dim $split[3]
Global $split = StringSplit($local_av_version, ":")
$1 = $split[1]
$2 = $split[2]
$variable = $split[3]

Dim $sourcetwo[2]
$sourcetwo = StringSplit($variable, "Time")
$DAT_Version = $sourcetwo[1]
$b = $sourcetwo[2]

$DAT_Ver = StringStripWS($DAT_Version,$STR_STRIPALL)
MsgBox(0, 'The McAfee DAT Version is....', "Results = " & $DAT_Ver)

 

Link to comment
Share on other sites

You could also do it like so:

$sString = ""
$sString &= "CommonShell Command Line Scanner Lite (VSCORE.15.5.0.3960)" & @LF
$sString &= "    Engine version: 5800.7501" & @LF
$sString &= "    DAT version:    8450.0" & @LF
$sString &= "    Time required:  15 milliseconds" & @LF

$aString = StringSplit($sString, @LF)
For $i = 1 To $aString[0]
    If StringInStr($aString[$i], "DAT Version:") Then $sDATVersion = StringStripWS(StringReplace($aString[$i], "DAT Version:", ""), 8)
Next
ConsoleWrite($sDATVersion & @CRLF)

 

Link to comment
Share on other sites

 

#include <Constants.au3>

Global $DOS, $Message = ''

$DOS = Run(@ComSpec & " /c C:\Progra~1\Common~1\McAfee\SystemCore\csscan.exe -Versions", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$sString = StdoutRead($DOS)

$aString = StringSplit($sString, @LF)
For $i = 1 To $aString[0]
    If StringInStr($aString[$i], "DAT Version:") Then $sDATVersion = StringStripWS(StringReplace($aString[$i], "DAT Version:", ""), 8)
Next
MsgBox(0,"", "DATVersion=" & $sDATVersion & @CRLF)

 

Link to comment
Share on other sites

What is the "," for in your example? There is no "," in the example data to split at :huh:

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

or
 

#include <Array.au3>
$sString  = "    Engine version: 5800.7501" & @LF
$sString &= "    DAT version:    8450.0" & @LF
$sString &= "    Time required:  15 milliseconds" & @LF

$array1 = StringRegExp($sString,"DAT version:\s*(\d+\.?\d*)",1)
_ArrayDisplay($array1)

the regex reads:
"DAT version" then zero or more spaces then one or more digits then zero or one fullstop then zero or more digits

Link to comment
Share on other sites

I see. Good night :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...