Jump to content

Recommended Posts

Posted (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?

:mellow:

Above is just an example, the numbers can be others and change often.

Edited by jorgeng
Posted

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.

:mellow:

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
Posted (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 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!"

Posted

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.75

and i want

15:47 ORDER "sl) Omx Sarlacc - Sälj Trade - Rosa - Krypterat OMXS300G" kurs 1012.25

How to do that?

:mellow:

Posted

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?

:mellow:

Posted

$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!"

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
  • Recently Browsing   0 members

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