jorgeng Posted June 18, 2008 Posted June 18, 2008 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)
monoceres Posted June 18, 2008 Posted June 18, 2008 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) Broken link? PM me and I'll send you the file!
weaponx Posted June 18, 2008 Posted June 18, 2008 (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 June 18, 2008 by weaponx
jorgeng Posted June 18, 2008 Author Posted June 18, 2008 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?
weaponx Posted June 18, 2008 Posted June 18, 2008 $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)
sandyd Posted June 18, 2008 Posted June 18, 2008 Have you tried just reading the whole file into a variable and doing StringReplace() function? ----[ SandyD ]---
weaponx Posted June 18, 2008 Posted June 18, 2008 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.
jorgeng Posted June 18, 2008 Author Posted June 18, 2008 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.
weaponx Posted June 18, 2008 Posted June 18, 2008 (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 June 18, 2008 by weaponx
jorgeng Posted June 18, 2008 Author Posted June 18, 2008 (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 June 18, 2008 by jorgeng
weaponx Posted June 18, 2008 Posted June 18, 2008 (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 June 18, 2008 by weaponx
jorgeng Posted June 18, 2008 Author Posted June 18, 2008 Almost there. I don't want to change the 9 by hand, just reading 9 from input-variable.
weaponx Posted June 18, 2008 Posted June 18, 2008 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?
jorgeng Posted June 18, 2008 Author Posted June 18, 2008 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.
Moderators SmOke_N Posted June 18, 2008 Moderators Posted June 18, 2008 $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.
weaponx Posted June 18, 2008 Posted June 18, 2008 $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?
Moderators SmOke_N Posted June 18, 2008 Moderators Posted June 18, 2008 (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 June 18, 2008 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.
weaponx Posted June 18, 2008 Posted June 18, 2008 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)
Moderators SmOke_N Posted June 18, 2008 Moderators Posted June 18, 2008 (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 June 18, 2008 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.
weaponx Posted June 18, 2008 Posted June 18, 2008 I know i've said it before but we need: -Native regex Split -Revamped StringRegExp() documentation + examples -More StringRegExpReplace() examples (There's only one!)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now