Sign in to follow this  
Followers 0
skippynz

removing some text from a string

9 posts in this topic

hi guys - ive got this script im writing that checks logs and then emails them to the helpdesk etc - but for some reason the the first part of the log shows ok in the email but the last section doesnt put in the @CRLF - each line just carries on from where the last one left off

so what i was wondering is there a way of removing some of the text cause i think that may be hampering it

[01/19/2006-20:15:54 ,0,0,0,0,0,2,0,0,0] Job No....................... 2

i was wanting to remove the bolded part of text - i found stringmid but that extracts that part and removes the rest which is what i want to keep

any ideas ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$s_line = "[01/19/2006-20:15:54 ,0,0,0,0,0,2,0,0,0] Job No....................... 2"

$s_newline = StringReplace($s_line,StringMid($s_line,21,19),"")

MsgBox(0,"test","Before: " & $s_line & @LF & "After  : " & $s_newline)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

$s_line = "[01/19/2006-20:15:54 ,0,0,0,0,0,2,0,0,0] Job No....................... 2"

$s_newline = StringReplace($s_line,StringMid($s_line,21,19),"")

MsgBox(0,"test","Before: " & $s_line & @LF & "After  : " & $s_newline)

the only issue is that the text may change from time to time. ie just check 2 logs the ,0,0,0,0,0,2,0,0,0 has changed from ,0,0,0,0,0,2,1,0,0

Share this post


Link to post
Share on other sites

As long as the characters are the same length, gary's solution will work.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

GaFrost is just showing you an example of how it can be done. The actual coding is up to you.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Local $s_newline
Local $s_line = "[01/19/2006-20:15:54 ,0,0,0,0,0,2,0,0,0] Job No....................... 2"
_StripIt($s_line, $s_newline, 21, 19)
MsgBox(0, "test", "Before: " & $s_line & @LF & "After  : " & $s_newline)

$s_line = "[01/19/2006-20:15:54 ,0,0,0,0,0,2,1,0,0] Job No....................... 2"
_StripIt($s_line, $s_newline, 21, 19)
MsgBox(0, "test", "Before: " & $s_line & @LF & "After  : " & $s_newline)

Func _StripIt(ByRef $s_old, ByRef $s_new, $start, $len)
   $s_new = StringReplace($s_old, StringMid($s_old, $start, $len), "")
EndFunc ;==>_StripIt

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

sorry yeah your first one worked, however now when its running it seems to be adding 1 on a blank line...

[01/20/2006-03:28:50]

1

[01/20/2006-03:28:50] Totals For................... Job

[01/20/2006-03:28:50] Total Session(s)............. 2

[01/20/2006-03:28:50] Total Directories............ 85,632

[01/20/2006-03:28:50] Total File(s)................ 855,517

[01/20/2006-03:28:50] Total Skip(s)................ 0

[01/20/2006-03:28:50] Total Size (Disk)............ 286,787.22 MB

[01/20/2006-03:28:50] Total Size (Media)........... 289,856.62 MB

[01/20/2006-03:28:50] Elapsed Time................. 7h 12m 13s

[01/20/2006-03:28:50] Average Throughput........... 670.60 MB/min

[01/20/2006-03:28:50] Total Error(s)/Warning(s).... 0/2

[01/20/2006-03:28:50]

1

[01/20/2006-03:28:50] Backup Operation Incomplete.

1

this is the code im using now. - ive found that i needed to put this line in "$backup1 = StringStripCR ($backup[$x])" so the emails i get are formated correctly... also the spacing at the end of the filewriteline are for the same reason

_FileReadToArray($latest ,$backup)
For $x = 1 to $backup[0]
    $backup1 = StringStripCR ($backup[$x])
    $backup2 = StringReplace($backup1,StringMid($backup1,21,19),"")
    FileWriteLine( @ScriptDir & "\checks.txt", $backup2 & "   ")
Next

any ideas on the newly aquired 1 on the end of blank lines

Edited by craig.gill

Share this post


Link to post
Share on other sites

_FileReadToArray($latest ,$backup)
For $x = 1 to $backup[0]
    If $backup[$x] <> '' Then $backup2 = StringReplace($backup[$x],StringMid($backup[$x],21,19),"")
    FileWriteLine( @ScriptDir & "\checks.txt", $backup2 & "   ")
Next


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

_FileReadToArray($latest ,$backup)
For $x = 1 to $backup[0]
    If $backup[$x] <> '' Then $backup2 = StringReplace($backup[$x],StringMid($backup[$x],21,19),"")
    FileWriteLine( @ScriptDir & "\checks.txt", $backup2 & "   ")
Next

thanks for that its working a treat now....

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