Jump to content

StringReplace in html file


autoitxp
 Share

Recommended Posts

hi how to StringReplace in html file help needed im trying this

$file = FileOpen("c:\_windows.html", 1)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$chars = FileRead($file, 99999999)
MsgBox(0, "Char read:", $chars)
$var = StringReplace($chars, "{RSHIFT}", "")
MsgBox(0, "Char read:", $var)
filewrite($file , $var)

FileClose($file)
Edited by autoitxp
Link to comment
Share on other sites

Link to comment
Share on other sites

hi how to StringReplace in html file help needed im trying this

$file = FileOpen("c:\_windows.html", 1)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$chars = FileRead($file, 99999999)
MsgBox(0, "Char read:", $chars)
$var = StringReplace($chars, "{RSHIFT}", "")
MsgBox(0, "Char read:", $var)
filewrite($file , $var)

FileClose($file)
You can't write to a file that's open in Read mode. Use this to test your proceedure then you can make changes without overwriting the original file.

$file = "c:\_windows.html"
If Not FileExists$file) Then
    MsgBox(0, "Error", "Unable to locate file.")
    Exit
EndIf

$chars = FileRead($file)
;MsgBox(0, "Char read:", $chars)
$Chars = StringReplace($chars, "{RSHIFT}", "")
;MsgBox(0, "Char read:", $chars)
;$nFile = FileOpen($File, 2)
$nFile = FileOpen(@DesktopDir & "\Test.txt", 2)
filewrite($,nfile , $chars)
FileClose($nfile)
ShellExecute(@DesktopDir & "\Test.txt")

Edit: I should have added this;

IF you use the $var = FileOpen($File, 1) Method then you MUST FileClose($var) it and THEN $Var = FileOpen($File, 2) followed by another FileClose($Var) AFTER you have completed all of the FileWrite or FileWriteLine() operations.

You might also want to take a look at using _FileReadToArray() or StringRegExpReplace().

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Developers

thanks

one more trouble

like above code is replacing

{RSHIFT}

how i can avoid {RSHIT} from this type of string in page {RSHIT}MYTEXT

New key ? :)

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

thanks

one more trouble

like above code is replacing

{RSHIFT}

how i can avoid {RSHIT} from this type of string in page {RSHIT}MYTEXT

Aside from the Freudian typo indicating a troubled potty training when you were a child...

You can have a RegExp match a pattern only when it is NOT followed by another pattern. To replace all instances of "{RSHIFT}", but only if they are NOT followed by "MYTEXT" would be:

$sString = "{RSHIFT}Dingle{RSHIFT}Berry{RSHIFT}MYTEXT{RSHIFT} {RSHIFT}for{RSHIFT} {RSHIFT}you."
$sResult = StringRegExpReplace($sString, "\{RSHIFT\}(?!MYTEXT)", "")
MsgBox(64, "@error = " & @error, $sResult)

^_^

I'm having such geeky fun learning RegExp stuff...

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Since it's an html file I'm wondering about the whole {RSHIFT} thing anyway. I don't see where that is likely to be used in HTML code. If you want , you can pm me a copy of the file you're trying to read and I'll have a look at that.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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