Jump to content

StringReplace stops at half file


Roth
 Share

Recommended Posts

Hello,

I am trying to make a script that edits log file to something more easy to read - in the log file there are informations with money inserted etc. etc.  in format like 20000 and i want to change it to 200Kč and more things like changing text etc. etc.

The problem is that the StringReplace stops at circa half the file... the log file has 3000 - 10 000 lines (it depends how much the till is used and what time it is....).

So i want to ask, is the stringreplace somehow limited ? It looks like that it always stop at half file and no matter if its 3000 lines or 8000 lines (it starts from bottom and goes up)

or is this code wrong ?

$szText2 = FileRead($file2)
$szText2 = StringReplace($szText2, "20000", "200Kč")
FileWrite($file2,$szText2)

 

Thank you

Link to comment
Share on other sites

  • Moderators

Roth,

Could you please post an example file - it is always easier to deal with a real-world case.

M23

P.S. Welcome to the AutoIt forums.

 

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hello Melba23,

Script attached - i know it will be confusing to read but i just started with autoit, btw there is a StringRegExpReplace to remove blank lines because i though that is the problem but it also stops at half the page

 

P.S. If you know how to add another 100 stores with 5 SCO tills that have their own IPs with some easier way than i have in the script (3 so far and 2 not completed :D ) i would be really grateful

 

Edited by Roth
Link to comment
Share on other sites

  • Moderators

Roth,

I actually wanted an example of the file you are trying to manipulate!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ops Sorry,

script copies the log file from page then creates txt file and copies the text inside and saves and close it.

Example text:

2018/04/13,08:05:54.735,[INF],3599454578,,Change Given,0,CZK:50000:0:1/CZK:20000:0:1/CZK:5000:0:1/CZK:2000:0:1/CZK:500:0:1/CZK:200:0:2
2018/04/13,08:08:28.538,[INF],3599618563,,Deposit,0,CZK:10000:0:1

 

Link to comment
Share on other sites

  • Moderators

Roth,

So that is an example of a single line and you say there are some 3-10000 of them in the file. What is the EOL delimiter?

To explain: I am trying to see if I can reproduce your problem on a representative file - can you not post an example of a whole file?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Log ends with two blank lines if that is what you ask...

Throughout the file there are circa three more blank lines

The two lines i sent you are throughout the whole log file but ofc with different time, amount etc.

Link to comment
Share on other sites

  • Moderators

Roth,

And what is the EOL delimiter? How does the file signify a new line? @CRLF? @CR? @LF?

Could there possibly be some non-printing characters within it (which is what I suspect might be the problem)?

In your script you are saving the files to manipulate them later - why not just post one of them! Help us to help you!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Roth,

Using the half-modified file you posted, I recreated a larger file of over 10,000 lines and all instances of "20000" were successfully changed:

; Read in file snippet
$sSnipText = FileRead("Snip_Log.txt")

; Check how many "20000" we can find WITHOUT changing any of then
StringReplace($sSnipText, "20000", "") ; The answer was 5
ConsoleWrite(@extended & @CRLF) ; The answer was 5

; Create a new file of suffcient size
$sNew_Log = ""
For $i = 1 To 300
    $sNew_Log &= $sSnipText
Next
FileWrite("New_Log.txt", $sNew_Log)

Sleep(1000) ; Allow thew system to settle

; Read large file
$sLogText = FileRead("New_Log.txt")
; Replace the "20000" instances
$sChgText = StringReplace($sLogText, "20000", "200Kè")
; How many?
ConsoleWrite(@extended & @CRLF) ; The answer was 1500 which is what is expected
; Save the file
FileWrite("Chg_log.txt", $sChgText) ; Visual inspection confirms the change

Can you please let me have an ORIGINAL file - just as you get it from the web - as there must be something within that file which is causing the problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well, i think i know where might be the problem... for some reason it copies the text two times and then the script edits only the last copy.

But i can not figure out why the script copies the text two times ?

Because if i look at the log2.txt i can see there are only 333 lines but if run the script and download the same log file its saved two times in the txt...

Link to comment
Share on other sites

  • Moderators

Roth,

That is obvious now I look at the script:

$sText = FileRead($FILE2)
$sText = StringRegExpReplace(StringRegExpReplace($sText, "(\v)+", @LF), "(^\v*)|(\v*\Z)", "")
FileWrite($FILE2, $sText) ; Write the modified text <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Sleep(150)

$szText2 = FileRead($FILE2) ;FileGetSize($File2))
$szText2 = StringReplace($szText2, "20000", "200Kè")
FileWrite($FILE2, $szText2) ; Append the changed text <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Remember that FileWrite appends text to a file.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Roth,

Why write it at all the first time? Just keep the text as a variable until you have completed all the required steps and then write it just the once. Better still, use FileOpen in "overwrite" mode and then you will be sure to have just the final text.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

Why using the clipboard at all since this is asking for trouble?
What is wrong simply using fileread/write statements and ensuring you overwrite the original file?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Roth,

What he said!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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