Sign in to follow this  
Followers 0
jorgeng

String extract

37 posts in this topic

Hello!

I have a program generating text-alarm. i want to extract strings from the text:

10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000

11:00 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS308F" kurs 953.5000

12:17 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS308F" kurs 947.2500

What i want to is to have OMXS308F delivered to a string.

As you see OMXS308F has new position every time in string, so how do i read the 8 characters

from OMXS308F. I have tried with string left, mid without success.

Thanks for help

:)

Other thing i have successed on:

; Plocka ut typ av order, Buystop/Sellstop

$PositionType = StringMid($var_original, 28, 8)

MsgBox(0, "Typ av order:", $PositionType)

Share this post


Link to post
Share on other sites



Finns enklare sätt men detta funkar :)

$string='11:00 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS308F" kurs 953.5000'
$string=StringLeft(StringTrimLeft($string,StringInStr($string,"Okrypterat")+10),8)
MsgBox(0,"Här är din text;)",$string)

:P


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$string = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000'
$array = StringRegExp($string,"Okrypterat (\w*)", 3)
MsgBox(0,"",$array[0])

Edited by weaponx

Share this post


Link to post
Share on other sites

Thanks.

Now another tricky thing. I want to have OMXS308F replaced to OMXS30-8FT

every time the code runs.

This is because different trading companies have different names on same termin.

The logic would be, read OMXS308F in a string, insert letter - after OMXS30 and

letter 8 which changes every year, take letter F from OMXS308F, insert and add

letter T last.

Anyone knowing small autoit-code for this?

:)

Share this post


Link to post
Share on other sites

$string = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000'
$array = StringRegExp($string,"Okrypterat (\w*)", 3)
MsgBox(0,"",$array[0]);OMXS308F
$NewString = StringReplace($string,$array[0],"OMXS30-8FT")
MsgBox(0,"",$NewString)

Share this post


Link to post
Share on other sites

Have you tried just reading the whole file into a variable and doing StringReplace() function?


----[ SandyD ]---

Share this post


Link to post
Share on other sites

Have you tried just reading the whole file into a variable and doing StringReplace() function?

That would be fine but the replace value is unknown, constantly changing.

Share this post


Link to post
Share on other sites

Weaponx,

i tried but this OMXS30-8FT would change to OMXS30-8GT

next month, next year it will be OMXS30-9AT and so on so it doesn't work.

:)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Weaponx,

i tried but this OMXS30-8FT would change to OMXS30-8GT

next month, next year it will be OMXS30-9AT and so on so it doesn't work.

:)

What do you mean it doesn't work? You just have to change the text in StringReplace to the new format.

If you are saying that you will be updating the original string multiple times then we will have to use a different expression to allow for a dash in the string.

$string = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS30-8GT" kurs 951.0000'
$array = StringRegExp($string,'Okrypterat (.*)"', 3)
MsgBox(0,"",$array[0]);OMXS30-8GT
$NewString = StringReplace($string,$array[0],"OMXS30-9AT")
MsgBox(0,"",$NewString)
Edited by weaponx

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Sorry if i'm not clear what i want.

I want an autoit-script which replace OMXS308F to OMXS30-8FT by code.

I will not preparete the code or anything else, just letter-changing...

Next month OMXS308G would be changed to OMXS30-8GT

and so on

The string comes from an alarm-box automatic, no preparation.

Edited by jorgeng

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Sorry if i'm not clear what i want.

I want an autoit-script which replace OMXS308F to OMXS30-8FT by code.

I will not preparete the code or anything else, just letter-changing...

Well thats exactly what my example provides for you

You may have to do this:

$NewString = StringReplace($string,$array[0],$array[0] & "-9AT")

Edited by weaponx

Share this post


Link to post
Share on other sites

Almost there.

I don't want to change the 9 by hand, just reading 9 from input-variable.

:)

Share this post


Link to post
Share on other sites

Almost there.

I don't want to change the 9 by hand, just reading 9 from input-variable.

:)

Okay, we need a fresh start.

1. The string to be replaced is "OMXS308F"...is this something predefined or do we need to extract that from the string before replacing?

2. What is the input that will be received, is it just a number? Because you have -8FT at the end, where is that "T" from?

Share this post


Link to post
Share on other sites

Okay, we need a fresh start.

1. The string to be replaced is "OMXS308F"...is this something predefined or do we need to extract that from the string before replacing?

2. What is the input that will be received, is it just a number? Because you have -8FT at the end, where is that "T" from?

Well. OMXS308F comes from my termin deliver company in an alarm-section which i use. I take this and send it to another termin deliver company where their name-standard is different - OMXS30-8FT, so yes we have to extract the OMXS308F text, which next monday will change one letter to OMXS308G.

The T in 8FT is an extension the new termin deliver company has added to their name convention.

Share this post


Link to post
Share on other sites

$s = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000'
$s = StringRegExpReplace($s, '((OMXS\w{2}))((\w{2}))', '\1-\3T')
MsgBox(0, 0, $s)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

$s = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000'
$s = StringRegExpReplace($s, '((OMXS\w{2}))((\w{2}))', '\1-\3T')
MsgBox(0, 0, $s)
What effect do double parentheses have?

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

What effect do double parentheses have?

Hell if I know... I was messing around so much with it, that I didn't even bother to see if it worked without it :)

Edit:

And it doesn't the way I have it written... I'll be honest ... with RegExpReplace... I'm a novice at best, because the rules that apply to RegExp itself don't always seem to apply.

Edit2:

It seems it would be like using double brackets with a class in this case:

$s = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000' & @CRLF & _
'11:00 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS308F" kurs 953.5000' & @CRLF & _
'12:17 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS308F" kurs 947.2500'
$s = StringRegExpReplace($s, '(OMXS\w{2})((\w{2}))', '\1-\2T')
Seems to be the right way (presumptively)... Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hell if I know... I was messing around so much with it, that I didn't even bother to see if it worked without it :)

Edit:

And it doesn't the way I have it written... I'll be honest ... with RegExpReplace... I'm a novice at best, because the rules that apply to RegExp itself don't always seem to apply.

I don't understand either, I can't get StringRegExpReplace to NOT capture groups:

$string = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000'

;CORRECT - Captures OMXS308F

$array = StringRegExp($string,'(?:Okrypterat )(.+)"',3)

MsgBox(0,"",$array[0])

;WRONG - Captures Okrypterat OMXS308F"

$NewString = StringRegExpReplace($string,'(?:Okrypterat )(.+)"', "^$0^")

MsgBox(0,"",$NewString)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I don't understand either, I can't get StringRegExpReplace to NOT capture groups:

Check out the 2nd edit...

Edit:

Or even:

Snipped ... This one didn't work

Guess I need to ask if AutoIt uses the standard C++ Replace method that Google wrote for PCRE and study that to learn more.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I know i've said it before but we need:

-Native regex Split

-Revamped StringRegExp() documentation + examples

-More StringRegExpReplace() examples (There's only one!)

Share this post


Link to post
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
Sign in to follow this  
Followers 0