Jump to content

Removing selected text from a file?


 Share

Recommended Posts

I have an HTML file that looks something like this:

<html>
<B>18-08-2005 - 11:14:49 AM - EMOTE TDABot: </B>-- MurDa.LoVe needs 2 <i>more players in game</i> [ ap44 ]!<br>
<B>18-08-2005 - 11:15:20 AM - EMOTE TDABot: </B>-- Games: pearL 8 in A [ ar86 ] --  <br>
<B>18-08-2005 - 11:15:50 AM - EMOTE TDABot: </B>-- Tael_ needs 9 <i>more players in game</i> [ ap55 ]!<br>
<B>18-08-2005 - 11:16:05 AM - EMOTE TDABot: </B>-- WonDeR[GGL] needs 7 <i>more players in game</i> [ ar54 ]!<br>
<B>18-08-2005 - 11:16:36 AM - EMOTE TDABot: </B>-- pearL needs 2 <i>more players in an</i> allrandom game [ ar86 ]!<br>

And it goes on and on and on. My script is finished thus far, but I need to find a way to clean up the HTML file so it doesn't look so sloppy.

Would it be possible to remove all of the bold and italics tags? And also, would it be possible to get rid of the "- EMOTE TDABot: " part?

I'm not looking for somebody to make the whole thing for me, just to send me in the direction of a function or something.

Thanks :whistle:

Link to comment
Share on other sites

I'm not looking for somebody to make the whole thing for me, just to send me in the direction of a function or something.

Have a look at StringReplace(). Read the file and do a StringReplace() for each line.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

maybe this would help ( not sure exactly what you want )

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <String.au3>

Dim $result_3 = ""

$test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)

$R_loc = StringInStr($result, ".com", 0, -1)

$result_2 = StringLeft( $result, $R_loc +3)

If $result_2 <> $result_3 Then
    $result_3 = $result_2
;write the line to the file
    MsgBox(0,"test", "final result = " & $result_3)
EndIf

Hope it helps

8)

NEWHeader1.png

Link to comment
Share on other sites

@Valuater

not sure exactly what you want

Huh?! He clearly explained he wants to remove <b>, <i> and "- EMOTE TDABot: " from the file.

@Saytun

Quick and dirty...

#include <file.au3>

$inlog = "c:\in.log"
$outlog = "c:\out.log"
_FileReadToArray($inlog, $array)

For $i = 1 to $array[0]
    StringReplace($array[$i], "<i>", "", -1, 0)
    StringReplace($array[$i], "</i>", "", -1, 0)
    StringReplace($array[$i], "<b>", "", -1, 0)
    StringReplace($array[$i], "- EMOTE TDABot: </b>", "", -1, 0)
Next

$file = FileOpen($outlog, 2)
If $file = -1 Then
    MsgBox(16, "ERROR", "The output file couldn't be opened!")
    Exit
EndIf

For $i = 1 to $array[0]
    FileWriteLine($file, $array[$i])
Next

FileClose($file)

My UDFs: ExitCodes

Link to comment
Share on other sites

A quicker, simpler version:

$inlog = "c:\in.log"

$data = FileRead($inlog, FileGetSize($inlog))

$data = StringReplace($data, "<i>", "")
$data = StringReplace($data, "</i>", "")
$data = StringReplace($data, "<b>", "")
$data = StringReplace($data, "- EMOTE TDABot: </b>", "")

FileWrite($inlog, $data)

Edit: I decided to eliminate the $outlog

Edited by c0deWorm

My UDFs: ExitCodes

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...