Jump to content

Expression parsing


VicTT
 Share

Recommended Posts

Hmm..I'm looking to parse an expression of this type in the most efficient manner possible using AutoIt(rather than using a for-loop as I would have done in PASCAL/C, I would want to use AutoIt built-in String manipulation functions ):

:<text1>!~<text2>@<text3>

So if $s were this expression, I would need CLEAN and easy to read code to split $s into it's three main components..$text1,$text2,$text3..A function would be nice..

Edited by VicTT
Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

Suggestion:

Take it a step at a time. First StringSplit on "<" .. This gives you all your values "cleaned" on the left hand side, in an array.

Next, StringSplit each array item on ">", and you'll have the values you seek all cleaned in element [1] of the resulting arrays.

HTH

:whistle:

Edit: spelling!

Edited by trids
Link to comment
Share on other sites

I'll just settle with

$text1=StringMid($s,2,StringLen($s)-StringInStr($s,"!~"))
$text2=StringMid($s,StringInStr($s,"!~"),StringLen($s)-StringInStr($s,"@"))
$text3=StringMid($s,StringInStr($s,"@"),StringLen($s)); Doesn't matter how many chars anymore

Hope that works :whistle:..

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

Nope..didn't work..but this does..Very ugly for pure debuggish purposes

$s=InputBox("String Input",":<text1>!~<text2>@<text3>")
$text1=StringMid($s,2,StringInStr($s,"!~")-StringLen("!~"))
$text2=StringMid($s,StringInStr($s,"!~")+StringLen("!~"),StringLen($s)-StringInStr($s,"@"))
$text3=StringMid($s,StringInStr($s,"@")+StringLen("@"),StringLen($s)); Doesn't matter how many chars anymore
Msgbox(0,"Split",$text1&" "&$text2&" "&$text3)

Hopefully I'll make a general func to split stuff..and I've got the right ideas..bad thing is I gotta meet my gf in minus 20 minutes..Cyaz..

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

So if $s were this expression, I would need CLEAN and easy to read code to split $s into it's three main components..$text1,$text2,$text3..A function would be nice..

RegExp is your friend!

$test = ":text1!~text2@text3"
$vResult = StringRegExp($test, ":(.*)!~(.*)@(.*)", 1)
if @extended then
  msgbox(0,"",$vResult[0] & ":" & $vResult[1]  & ":" & $vResult[2])
else 
  msgbox(0,"ERROR", "Pattern not found")
endif

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...