Jump to content

Double the return value and add 2 to StringInStr(FileRead( for @LF


Recommended Posts

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 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 say
Artist: Middle Class Rut

Link to comment
Share on other sites

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 say
Artist: Middle Class Rut

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 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 say
Artist: Middle Class Rut

Link to comment
Share on other sites

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 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 say
Artist: Middle Class Rut

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