When using ReadLn, how would I select everything after a colon ":" and leave everything before it out of the variable? Reading through the forum I see using Regex as the solution but I'm unsure of the usage. Here is my code:
Let>RP_WAIT=1
Let>RP_ADMIN=1
Run>cmd.exe /c systeminfo >%TEMP_DIR%\sysinfo.txt
ReadLn>%TEMP_DIR%\sysinfo.txt,13,strLinemanufacure
ReadLn>%TEMP_DIR%\sysinfo.txt,14,strLinemodel
MessageModal>%strLinemanufacure%_%strLinemodel%
Any help would be great! Thank you!
ReadLn Everything After ":" Colon
Moderators: JRL, Dorian (MJT support)
- Dorian (MJT support)
- Automation Wizard
- Posts: 1416
- Joined: Sun Nov 03, 2002 3:19 am
Re: ReadLn Everything After ":" Colon
Hi MoonSpoon!
Here are three ways of doing this. My third solution is intended to help you understand some of the string handling functions in Macro Scheduler.
//Use Regex
//Use Separate
OR...
//More string handling examples to do the same thing.
Here are three ways of doing this. My third solution is intended to help you understand some of the string handling functions in Macro Scheduler.
//Use Regex
Code: Select all
Let>MyString=1234567890:QWERTYUIOP
RegEx>(?<=\:).*,MyString,0,matches,num,0
MessageModal>matches_1
Code: Select all
//Set up a sample string
Let>MyString=1234567890:QWERTYUIOP
//Use Separate
Separate>MyString,:,NewString
//If there's only one colon, everything before the colon will be in in NewString_1, and everything after in NewString_2
MessageModal>%NewString_1%
MessageModal>%NewString_2%
//More string handling examples to do the same thing.
Code: Select all
//Set up a sample string
Let>MyString=1234567890:QWERTYUIOP
//...we could use Position,then do some calculations
//Get the length of the string
Length>MyString,LenMyString
//Find the position of the colon
Position>:,MyString,1,ColonPos
//The part we're looking for is 1 position on from the colon
Let>AfterColonPos=ColonPos+1
//How long is the string we're looking for?
Let>StringAfterColon=LenMyString-ColonPos
//Now we know where everything is, extract that part of the string
MidStr>MyString,AfterColonPos,StringAfterColon,NewString
MessageModal>NewString
Re: ReadLn Everything After ":" Colon
@MoonSpoon
//Read your line.
ReadLn>YourPath\filename,3,nLine
//Remove everything before colon and the colon itself.
RegEx>(.*):(.*),nLine,0,match,nom,1,$2,RestOfLine
mdl>%RestOfLine%
The quotes create what is called a group. (.*) - This means put everything in a group.(.*=everything)
So it does that. But then the colon is outside that group. So, the match is only up to the colon not including the colon.
Now, the colon is used in the argument already. So the next group will be everything after the colon.
So... the next group says put everything else here.
Groups are referred to in the order that they occur. The first group is the first instance of (.*). The second is the second (.*).
.........nom,1,$2,RestOfLine
The 1 indicates you want to do a replacement.
The $2 indicates your replacement is group 2.
"RestOfLine" is the new string or replacement.(the result)
You have a basic idea even if you don't fully understand. Type out this RegEx and look at the command reference that tells what to type next. (at the bottom of the editor text screen)
match is an array. match_1,match_2.....
Each match that RegEx> finds will be an array. You do not have to use the word match. What ever suits you.
nom is the number of matches. I use nom. But again use what ever you like.
//Read your line.
ReadLn>YourPath\filename,3,nLine
//Remove everything before colon and the colon itself.
RegEx>(.*):(.*),nLine,0,match,nom,1,$2,RestOfLine
mdl>%RestOfLine%
The quotes create what is called a group. (.*) - This means put everything in a group.(.*=everything)
So it does that. But then the colon is outside that group. So, the match is only up to the colon not including the colon.
Now, the colon is used in the argument already. So the next group will be everything after the colon.
So... the next group says put everything else here.
Groups are referred to in the order that they occur. The first group is the first instance of (.*). The second is the second (.*).
.........nom,1,$2,RestOfLine
The 1 indicates you want to do a replacement.
The $2 indicates your replacement is group 2.
"RestOfLine" is the new string or replacement.(the result)
You have a basic idea even if you don't fully understand. Type out this RegEx and look at the command reference that tells what to type next. (at the bottom of the editor text screen)
match is an array. match_1,match_2.....
Each match that RegEx> finds will be an array. You do not have to use the word match. What ever suits you.
nom is the number of matches. I use nom. But again use what ever you like.
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!