jorgeng Posted June 16, 2010 Share Posted June 16, 2010 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) Link to comment Share on other sites More sharing options...
UEZ Posted June 16, 2010 Share Posted June 16, 2010 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
DW1 Posted June 16, 2010 Share Posted June 16, 2010 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) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
jorgeng Posted June 16, 2010 Author Share Posted June 16, 2010 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. Link to comment Share on other sites More sharing options...
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