jorgeng Posted June 28, 2010 Posted June 28, 2010 (edited) I have a string which looks like this: 15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75 I want to subtract 0.50 to 1012.75 giving me 1012.25. Is this possible to do in a calculation string? Above is just an example, the numbers can be others and change often. Edited June 28, 2010 by jorgeng
JohnOne Posted June 28, 2010 Posted June 28, 2010 Here is one example. $string='15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $a=StringRegExp($string,"kurs (\S*)",1) $b = $a[0] - 0.5 ConsoleWrite($b & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
PsaltyDS Posted June 28, 2010 Posted June 28, 2010 Extract that part of the string with StringMid() or other string manipulation, or maybe StringRegExp(). Do the math, then put the result back in the string. If you get stuck, post what you tried for more help. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Paulie Posted June 28, 2010 Posted June 28, 2010 $string='15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $result = stringregexp($string, "\d*\.\d{2}",3) If isarray($result) then $result = $result[0]-.5 Msgbox(0,"",$result) Endif
GEOSoft Posted June 28, 2010 Posted June 28, 2010 (edited) And another simple way $sStr = '15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $iNewValue = StringRegExpReplace($sStr, "^.+\h([\d.]+)$", "$1") -.5 If @Extended Then MsgBox(0, "Result", $iNewValue) Else MsgBox(0, "Error", "Invalid string entered") EndIf Edit: Added code to check for a valid string. Edited June 28, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
jorgeng Posted June 29, 2010 Author Posted June 29, 2010 Thanks everybody.They all works, but i want to have the result replaced in original string, how to do that?Now the string looks like:15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75and i want15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.25How to do that?
JohnOne Posted June 29, 2010 Posted June 29, 2010 $string='15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $a=StringRegExp($string,"kurs (\S*)",1) $b = $a[0] - 0.5 ConsoleWrite($b & @LF) $c = StringReplace($string,$a[0],$b) ConsoleWrite($c & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jorgeng Posted June 29, 2010 Author Posted June 29, 2010 $string='15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $a=StringRegExp($string,"kurs (\S*)",1) $b = $a[0] - 0.5 ConsoleWrite($b & @LF) $c = StringReplace($string,$a[0],$b) ConsoleWrite($c & @LF) Thanks, works great.
jorgeng Posted June 30, 2010 Author Posted June 30, 2010 One small problem, when price is 1012.50 and script will subtract 0.50 the result becomes 1012 and i want 1012.00 How to fix this?
GEOSoft Posted June 30, 2010 Posted June 30, 2010 $sStr = '15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.50' $aStr = StringRegExp($sStr, "^(.+\h)([\d.]+)$", 1) If IsArray($aStr) Then $aStr[1] = StringFormat( "%.2f", $aStr[1] -.5) $sStr = $aStr[0] & $aStr[1] MsgBox(0, "Result", $sStr) Else MsgBox(0, "Error", "Invalid string entered") EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
JohnOne Posted June 30, 2010 Posted June 30, 2010 Or $string='15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.75' $a=StringRegExp($string,"kurs (\S*)",1) $b = $a[0] - .5 If Not StringInStr($b,".") Then $b &= ".00" $c = StringReplace($string,$a[0],$b) ConsoleWrite($c & @LF) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
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