oemript Posted March 18, 2018 Share Posted March 18, 2018 Referring to following coding, $oMeta.GetAttribute('content') should insert a single line within text file. I would like to know on how to inital a file before FileWrite, so there is only a single line within text file. Sometimes, it gets a second line with "". $sURL = "www.sample.com" Local $oIE = _IECreate($sURL) $oMeta = _IEGetObjByName($oIE, 'og:url') ;ConsoleWrite($oMeta.GetAttribute('content') & @CRLF) ;MsgBox(0, "URL", StringReplace( $oMeta.GetAttribute('content') & @CRLF, "html/","html")) Local $hFileOpen = FileOpen("D:\Import.txt", 2) FileWrite($hFileOpen, StringReplace( $oMeta.GetAttribute('content') & @CRLF, "html/","html")) FileClose($hFileOpen) Does anyone have any suggestions on how to initial D:\Import.txt file and only insert a single line into file as well? Thanks in advance for any suggestions Link to comment Share on other sites More sharing options...
JohnOne Posted March 18, 2018 Share Posted March 18, 2018 Perhaps replace @CR and @LF individually, before write. Or Regex replace trailing whitespace. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
oemript Posted March 18, 2018 Author Share Posted March 18, 2018 4 hours ago, JohnOne said: Perhaps replace @CR and @LF individually, before write. Or Regex replace trailing whitespace. I would like to know on whether it is necessary to add @CRLF or not, if I only export a single string into text file. Do you have any suggestions? Thank you very much for any suggestions (^v^) Link to comment Share on other sites More sharing options...
xCROv Posted March 19, 2018 Share Posted March 19, 2018 (edited) Are you talking about creating the file by saying initial? Because FileWrite will create the file if it doesn't exist already. May need to clarify it a bit more so I understand. Edited March 19, 2018 by xCROv Link to comment Share on other sites More sharing options...
oemript Posted March 20, 2018 Author Share Posted March 20, 2018 (edited) FileWrite is suitable to my situation, which would create a file on existed and non-existed situation, FileWrite($hFileOpen, StringReplace( $oMeta.GetAttribute('content'), "html/","html")) When I insert text into text file, I prefer only include the content without any special char at all. Such as if text contains "ABC" then only insert "ABC" into specific text file, that is all. Considering FileWrite need to export text into existing file, so what to do in order to erase all texts within text file and insert "ABC" into it, so the specific text file only contain "ABC" under this situation. Do you have any suggestions? Thanks, to everyone very much for any suggestions (^v^) Edited March 20, 2018 by oemript Link to comment Share on other sites More sharing options...
jchd Posted March 20, 2018 Share Posted March 20, 2018 FileDelete the file before FileWrite to it. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
rudi Posted March 20, 2018 Share Posted March 20, 2018 (edited) Hello, $hFileOpen = FileOpen("D:\Import.txt", 2) ... will open an empty file for write. This means, in case the file already exists, its content will be erased. If it didn't exist already, a new file will be created. FileWrite($hFileOpen,$YourString) ... will write your string to that file without adding a @CRLF at the end of the line that string was written to. In case you see a trailing empty line in your file, the string $YourString has a "trailing LINEFEED" at it's end. To cleanup that one use either StringStripWS() or StringRegExReplace() before writing the string to your file. You can use ... ConsoleWrite("""" & $YourString & """" & @CRLF) ... to see in the output pane of SciTE the result of writing your string to your file Regards, Rudi. Edited March 20, 2018 by rudi oemript 1 Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
oemript Posted March 21, 2018 Author Share Posted March 21, 2018 (edited) I would like to know on how to assign different encoding for export text file. Do you have any suggestions? Thanks, to everyone very much for suggestions (^v^) Edited March 21, 2018 by oemript Link to comment Share on other sites More sharing options...
rudi Posted March 21, 2018 Share Posted March 21, 2018 Hi. Please give an example of the STRING you have to process, and how you expect the CSV line in your export file to look like. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
oemript Posted March 22, 2018 Author Share Posted March 22, 2018 (edited) If I prefer big-5 encoding instead of utf-8, what kind of coding should be inserted before FileWrite? Do you have any suggestions? Thanks, to everyone for any suggestions (^v^) Edited March 22, 2018 by oemript Link to comment Share on other sites More sharing options...
Developers Jos Posted March 22, 2018 Developers Share Posted March 22, 2018 3 hours ago, oemript said: what kind of coding should be inserted before FileWrite? Have you tried with your originally posted code setting the appropriate value for parameter 2, thus including $FO_UTF16_BE_NOBOM (2048) = Use Unicode UTF16 Big Endian (without BOM) reading and writing mode. Jos 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...
oemript Posted March 24, 2018 Author Share Posted March 24, 2018 I would look into it Thanks, to everyone very much for suggestions (^v^) 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