Sign in to follow this  
Followers 0
jorgeng

Cut zeroes

4 posts in this topic

I have a string in a file which is like this:

17:24 ORDER "sl) Omx Sarlacc - Nollställ Depå - Krypterat OMXS300F" kurs 1045.7500$

I want to cut two zeroes after the price meaning i want the string to look like this:

17:24 ORDER "sl) Omx Sarlacc - Nollställ Depå - Krypterat OMXS300F" kurs 1045.75$

I write the string to a file today by doing this and want now to write the file without

four digits, just two digits, anyone having an idea how to cut two digits?

FileDelete("C:\Filer\Rankor System\Omx_Sarlacc_Trades_PHP_Mangold.txt")

$file_Omx_Sarlacc_PHP_Mangold = FileOpen("C:\Filer\Rankor System\Omx_Sarlacc_Trades_PHP_Mangold.txt", 1)

;Check if file opened for writing OK

If $file_Omx_Sarlacc_PHP_Mangold = -1 Then

MsgBox(4096, "Error", "Unable to open file Omx_Sarlacc_PHP_Mangold.",2)

Exit

FileWrite($file_Omx_Sarlacc_PHP_Mangold, $var_original)

;MsgBox(4096, "Trade", $file_Omx_Sarlacc_PHP_Mangold)

FileClose($file_Omx_Sarlacc_PHP_Mangold)

Share this post


Link to post
Share on other sites



Here my suggestion:

$line = '17:24 ORDER "sl) Omx Sarlacc - Nollställ Depå - Krypterat OMXS300F" kurs 1045.7500$'

$aStrReg = StringRegExp($line, ".+kurs ([\d].+)", 3)
$new = Round(StringLeft($aStrReg[0], StringLen($aStrReg[0]) - 1), 2) & "$"
$line = StringReplace($line, $aStrReg[0], $new)

ConsoleWrite($line & @CRLF)

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ's works well. Another option, if all of the lines follow that syntax, would be just the string replacement:

$line = '17:24 ORDER "sl) Omx Sarlacc - Nollställ Depå - Krypterat OMXS300F" kurs 1045.7500$'
$new = StringReplace($line, '00$', '$')
ConsoleWrite($new & @CRLF)

Share this post


Link to post
Share on other sites

UEZ's works well. Another option, if all of the lines follow that syntax, would be just the string replacement:

$line = '17:24 ORDER "sl) Omx Sarlacc - Nollställ Depå - Krypterat OMXS300F" kurs 1045.7500$'
$new = StringReplace($line, '00$', '$')
ConsoleWrite($new & @CRLF)

Thanks,

I try this, seems simplier since all lines has the same syntax.

:mellow:

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