Jump to content
meows

The stringleft stopped working for me

Recommended Posts

meows

I need to trim the date and accessed times from a file list. It totals 22 spaces need to be trimmed, and I can't seem to get any trimmed.

#include <FileConstants.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $iRead ,$s2String

IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", $s2String)
$iRead=IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", "")
$sString=$iRead
;MsgBox($MB_SYSTEMMODAL, "", $sString)
Local Const $sFilePath = $iRead & "\my.log"
;MsgBox($MB_SYSTEMMODAL, "", $sFilePath)
  Local $hFileOpen = FileOpen($sFilePath, $FO_READ)
    Local $sFileRead = FileRead($hFileOpen)
 ; MsgBox($MB_SYSTEMMODAL, "", $sFileRead)

  $string_variable = $sFileRead
$trimmed = StringTrimLeft ($string_variable, 9)
;Local $sFileRead = StringTrimLeft("",22)
MsgBox($MB_SYSTEMMODAL, "", $string_variable)
;;;;;;;;;;;;;;;;;;;;;;;;;("fileList.txt"= $string_variable)

;FileMove ($string_variable,"fileList.txt")
 ;  FileClose($hFileOpen)
Exit

the file list is attached, 

I guess if i knew out how to make a file list with out time and date stamps would be easier. 

Any advice would be of great help.

my.7z

Share this post


Link to post
Share on other sites
mikell

?

Local $hFileOpen = FileOpen("my.log", 0)
Local $new = ""
While 1
    $line = FileReadLine($hFileOpen)
    If @error Then Exitloop
    $line = StringTrimLeft($line, 22)
    $new &= $line & @crlf
Wend
FileClose($hFileOpen)
FileWrite("my_new.log", $new)

and another way

$txt = FileRead("my.log")
$new = StringRegExpReplace($txt, '(?m)^.*:\h', "")
FileWrite("my_new.log", $new)
Edited by mikell

Share this post


Link to post
Share on other sites
Melba23

meows,

Firstly you are reading the whole file into a single variable, so you would only ever remove the first few characters of the first line - and then you are showing the untrimmed variable in the MsgBox so you never actually see the trimmed version.

I suggest reading the file into an array and then trimming each element - something like this:

#include <MsgBoxConstants.au3>

Local $iRead, $s2String

IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", $s2String)
$iRead = IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", @ScriptDir)

Local Const $sFilePath = $iRead & "\my.log"
Local $aFileRead = FileReadToArray($sFilePath) ; Read into an array

For $i = 0 To UBound($aFileRead) - 1
    $string_variable = $aFileRead[$i]               ; Read each element in turn
    $trimmed = StringTrimLeft($string_variable, 22) ; Trim it
    MsgBox($MB_SYSTEMMODAL, "", $trimmed)           ; Show trimmed variable and not original
Next

Exit
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

 

Share this post


Link to post
Share on other sites
meows

 

?

Local $hFileOpen = FileOpen("my.log", 0)
Local $new = ""
While 1
    $line = FileReadLine($hFileOpen)
    If @error Then Exitloop
    $line = StringTrimLeft($line, 22)
    $new &= $line & @crlf
Wend
FileClose($hFileOpen)
FileWrite("my_new.log", $new)

and another way

$txt = FileRead("my.log")
$new = StringRegExpReplace($txt, '(?m)^.*:\h', "")
FileWrite("my_new.log", $new)

 

Many thanks.. brain was fried. your a life saver!

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

×