autoitxp Posted December 19, 2007 Share Posted December 19, 2007 (edited) 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 December 19, 2007 by autoitxp Link to comment Share on other sites More sharing options...
Jex Posted December 19, 2007 Share Posted December 19, 2007 (edited) #include <IE.au3> $oIE = _IECreate("c:\_windows.html", 0, 0) $Source = _IEDocReadHTML($oIE) $Replace = StringReplace($Source, "Test123", "...") FileWrite("Test.txt", $Replace) _IEQuit($oIE) Like that get source and replace strings in source ? Edited December 19, 2007 by Jex My scripts : Immediate Window , My Web Browser , Travian , Text Effect , Characters & Words per minute or second , Image Editor (ImageMagick) , Matrix style background effect ( Screensaver ) , Mail Sender , Protectlinks decoder and Rapidshare links checker , Fonts Fetcher , Region determine , Compare pictures , Gradient color box , Mouse Coordinates, Colors, Pixel Search things , Encrypt/Decrypt and embeding file in jpeg thing , Hard disk space monitor , Reflex game , Multiplayer Tic Tac Toe , WLM ( MSN ) personal message changer Link to comment Share on other sites More sharing options...
GEOSoft Posted December 19, 2007 Share Posted December 19, 2007 (edited) 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 December 19, 2007 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 More sharing options...
autoitxp Posted December 19, 2007 Author Share Posted December 19, 2007 thanks one more trouble like above code is replacing {RSHIFT} how i can avoid {RSHIT} from this type of string in page {RSHIT}MYTEXT Link to comment Share on other sites More sharing options...
Developers Jos Posted December 19, 2007 Developers Share Posted December 19, 2007 thanks one more trouble like above code is replacing {RSHIFT} how i can avoid {RSHIT} from this type of string in page {RSHIT}MYTEXTNew 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 More sharing options...
autoitxp Posted December 19, 2007 Author Share Posted December 19, 2007 New key? What ? Link to comment Share on other sites More sharing options...
DW1 Posted December 19, 2007 Share Posted December 19, 2007 LOL LOL LOL, I wish I had a couple shit keys too I am not sure what you are asking... it looks like you are already removing your RSHIFT's AutoIt3 Online Help Link to comment Share on other sites More sharing options...
GaryFrost Posted December 19, 2007 Share Posted December 19, 2007 Shitty keyboard? SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
autoitxp Posted December 19, 2007 Author Share Posted December 19, 2007 Shitty keyboard? lol lol aha i got your point these keys come from database entry and saved in file files some of text need to be trimmed hehe! Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 19, 2007 Share Posted December 19, 2007 (edited) 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 December 19, 2007 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 More sharing options...
GEOSoft Posted December 19, 2007 Share Posted December 19, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now