souldjer777 Posted February 14, 2020 Posted February 14, 2020 (edited) Good Morning, This is very odd - but I'm sure the AutoIT experts know the root cause of the issue that I'm experiencing. I have multiple CSV files that I'm combining and I wasn't able to figure out why StringInStr wasn't returning the proper value for the "@LF" at the end of the CSV header. StringInStr kept returning a value of "104" ... $iFirstChar2ndLine = StringInStr(FileRead($sFilePathInput01 & "/" & $FolderName01 & "/" & $a_CSVFileListExtactToArray01[$i]), @LF, 0, 1) So I just started playing around with static values - My first thought was to double the StringInStr value... So I plugged in the StringInStr value of 104 x 2 and added the "LF" +2 which was a total of 210. This works believe it or not - but I still don't know why and I'm not 100% sure it's correct. If I open the CSV files in Notepad++ I see "UCS-2 LE BOM" which translates to "USC-2 Little Endian" I'm guessing? So if the file in Notepad++: "UCS-2 Little Endian" then that is equal to AutoIt Notation: "UTF16 Little Endian" according to AutoIt "Unicode Support" so that's how I'm opening the files. https://www.autoitscript.com/autoit3/docs/intro/unicode.htm $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode. Not all that confident with the different file types... I'd appreciate positive feedback. I have been in the "Help" file for about 2 days lol so please don't reference see AutoIt "Help" please - I just need more of a human explanation maybe. Thanks All! Edited February 14, 2020 by souldjer777 "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
Subz Posted February 14, 2020 Posted February 14, 2020 Can you post an example csv file? StringInStr should just return the position of @LF but without an example can't tell what the actual position should be.
souldjer777 Posted February 14, 2020 Author Posted February 14, 2020 Time Period Time zone Domain Email Subject Email To Email From Protection Method Matched content ActionLF This is the CSV header that returns the value of 104. So for example that is "Time(Space)Period(TAB)Time(Space)zone(TAB)" ... "Action(LINE FEED)" I was trying to keep the CSV header out of the combined CSV files. The rest of the data is work only so I can't post... sorry. Thanks again! "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
Subz Posted February 14, 2020 Posted February 14, 2020 Don't really understand what you're trying to achieve, 104 is the position of @LF Local $sString = "Time Period" & @TAB & "Time zone" & @TAB & "Domain" & @TAB & "Email" & @TAB & "Subject" & @TAB & "Email To" & @TAB & "Email From" & @TAB & "Protection Method" & @TAB & "Matched content Action" & @LF $sString &= "Line Two" & @TAB & "xxxx xxxx" & @TAB & "xxxxxx" & @TAB & "xxxxx" & @TAB & "xxxxxxx" & @TAB & "xxxxx xx" & @TAB & "xxxxx xxxx" & @TAB & "xxxxxxxxxx xxxxxx" & @TAB & "xxxxxxx xxxxxxx xxxxxx" & @LF Local $iString = StringInStr($sString, @LF, 0, 1) ConsoleWrite("@LF found at position: " & $iString & @CRLF) ConsoleWrite("Remove first line: " & StringTrimLeft($sString, $iString))
souldjer777 Posted February 14, 2020 Author Posted February 14, 2020 (edited) That's what I'm essentially confused about - A partial CSV header shown below - from all remaining CSV files written to the main CSV file would be the result of using that returned StringInStr value of 104 Email From Protection Method Matched content Action The above data equals:(TAB)Email(Space)From(TAB)Protection(SPACE)Method(TAB)Matched(SPACE)content(TAB)Action(LINE FEED) It's very confusing. FileSetPos($hFileOpenRead, $iFirstChar2ndLine, 0) FileWrite($hFileOpenWrite, FileRead($hFileOpenRead)) FileClose($hFileOpenRead) Again, I believe - but I'm not certain - that it's the file type / code... UPDATE: Sorry, the CSV header didn't copy into this post - Just added now - It will be copied into the main file again and again using StringInStr returned value of 104. Edited February 14, 2020 by souldjer777 "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
Subz Posted February 14, 2020 Posted February 14, 2020 It all depends if @LF is always at pos 104, but without any example code or text, really unsure where the issue is. Personally I would just use _FileReadToArray to read the file to an array, then use _ArrayToString and skip the first line item.
souldjer777 Posted February 14, 2020 Author Posted February 14, 2020 I hear ya Subz - Thank you. I know, I just got obsessed with trying to fix this and trying to figure out the root cause. "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
souldjer777 Posted February 14, 2020 Author Posted February 14, 2020 (edited) Dangit, yeah... looks like that's what I'll end up doing - so frustrating but I like arrays so all good UPDATE - It's failing on _FileReadToArray on some CSV files with @TAB delimiter - great... more problems lol... have to stay at "Default" until I figure this out. Edited February 14, 2020 by souldjer777 "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
FrancescoDiMuro Posted February 15, 2020 Posted February 15, 2020 @souldjer777 Fortunately, _FileReadToArray() tells you what's wrong with the @error macro, so just display it (in case of error), and check the Help file Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
mikell Posted February 15, 2020 Posted February 15, 2020 17 hours ago, souldjer777 said: I was trying to keep the CSV header out of the combined CSV files If the final purpose is to remove the first line (header) from the csv, there are easier ways to do that Example : $new = StringRegExpReplace($txt, '^\N+\R', "")
junkew Posted February 21, 2020 Posted February 21, 2020 If you want to understand how files are actually written on a filesystem use a hex editor then you can clearly see it in a raw format before its interpreted. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
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