Jump to content

Preform FileReadLine Operation on String Data not File


Go to solution Solved by guinness,

Recommended Posts

Topic: Add Line Numbers to Data Inside a Array

Q. How to parse  string data at @LF. @CR, or CRLF & format into numbered lines stored inside an array using regular expressions.

Case Scenario: Data is stored on a server or otherwise remotely and needs to be read and processed internally within the application without creating temp files for the data to be outputted to.

Accepted Answers:

@guinness 

#include <Array.au3>

Local $sData = BinaryToString(_Data())
Local $aSRE = StringRegExp('Count' & @CRLF & $sData, '([^\r\n]*)(?:\r\n|\n|\r)(?:[\r\n]$)?', 3)
$aSRE[0] = UBound($aSRE) - 1
_ArrayDisplay($aSRE)

Func _Data()
    Return '0x48656C6C6F20506C616E65740D0A576F726C64206F72646572206973206F76657272617465640D0A53616C6C7920' & _
            '73656C6C73207365617368656C6C7320646F776E206279207468652073656173686F726520626563617573652E2E2E' & _
            '0D0A2E2E2E53616C6C7920697320616E20756E656D706C6F796564206869707069652E0D0A'
EndFunc   ;==>_Data

Read:

Initial Topic & Question

Topic: FileReadLine Operation on Data String not File

Q. How do you preform a FileReadLine operation when there is no physical file and without
   creating a temp file to store the data?

Case Scenario: Data is stored remotely.

Edited by UnKnOwned
Link to comment
Share on other sites

Where is the data stored then?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Why are you writing your question into a spoiler? Further I don't understand what your question is?

Or is this a riddle?

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@guinness

On a server. For arguments sake lets just say a webpage and we will do it in the form of _INetGetSource()

I would like to do this.

Local $file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    Local $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
WEnd

FileClose($file)

...on the returned _INetGetSource() data

This requires parsing of the data, I know.

What I am wondering, is if there is a already preexisting Autoit function for this or if one has to be made?

@UEZ

Because, if you only do what everyone else does, surely you will never evolve into your own.

I guess I could have gone down the road of

Q. How do you preform a FileReadLine operation when there is no physical file and without
     creating a temp file to store the data?

Case Scenario: Data is stored remotely. 

Just testing things out, didn't feel like wasting server space here testing out features. I can take out two birds with one stone this way.

The second question is answered above in this post.

Your final question, stop asking me rhetorical questions, or is this a question?  

:shifty:

Edited by UnKnOwned
Link to comment
Share on other sites

Firstly there is a test section designed for testing features of the Forum. Secondly, StringSplit, StringRegExp, actually most of the String functions. You have to be more specific with the word 'parse', parse what exactly? Lines ending with r n?

#include <Array.au3>

Local $sData = 'sData_1' & @CRLF & 'sData_2' & @CRLF & 'sData_3'
Local $aArray = StringSplit($sData, @CRLF, 1)
_ArrayDisplay($aArray)

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@guinness

My apologies, I knew to after rereading my response posted. You must be very exact in your phrasing when it comes to the internet. I just figured with the server reference it would be common sense, but I guess I should have been more specific with the "here's". When I said without wasting server space I was referring to that section of the forums that is designated for such testing. I did not want to waste space there just to see what I like for just a couple of formatting features. Since I am only really using or testing but a couple forum features it is more logical to consolidate the little space really, but more so the content  when needing to refer back to what I have used and or posted.

Now,

Lets stay away from StringReg as it is slower than my wife getting out of bed in the morning.

The file for now will just be a plain text file, and inside it will have content like this.

Chop Chop
If I can understand you then why can't you understand me, and I'm an novice moron.
Line number 3
Line number 4

If we grab the data from the file & write it out on the clients end the formatting will remain as it should be, but while the data is still raw it is formatted

Chop Chop If I can understand you then why can't you understand me, and I'm an novice moron. Line 3 Line 4

Until it is printed out there is no way to determine line numbers as there are none. So, lets parse the text at the line feed.

While the data is still raw turn it into virtual lines whereas

Chop Chop would be line 1

Some examples?

Link to comment
Share on other sites

Without proof I don't believe your statement about StringRegExp.

I still can't fathom what you want. Just post a before and after and then maybe I will understand.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

If we were speaking in literal terms and I could prove it, I would have a viral YouTube video and a new science project. Retirement would come early and the holidays would be something to look forward to.

Pseudo

INetGetSource('http://www.somesite/File.txt')
Readin line by line of the file, store it in a array maybe?
Data is now stored and ready for use
get data from virtual line 1

And or, amuse me with some regular expressions.

Link to comment
Share on other sites

And or, amuse me with some regular expressions.

I'm not going to waste my time, just to have you either call me stupid or say it doesn't work. From your comments I believe you have little to no knowledge of regular expressions and thus deem them slow.

Look at StringInStr, StringMid, StringLeft and/or StringSplit. What you want is pretty easy to achieve, in fact do you bother to look at the StringSplit example above.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@guinness

I think perhaps you and I have gotten off on the wrong foot, or maybe too many newcomers to these forums like myself have abused those who have tried to help others.

So, let me be the first to apologize if anything I have stated thus far has given you the impression that either A you are wasting your time with me or B that I would degrade any response as I am sure a response given by you would be just, and respected coming from someone whom obviously knows the language much more in depth than myself.

I am clearly not a teenager, I carry with me no ego, only a thirst for knowledge and understanding. I treat all people the same from the janitor to the president. ;)

If I have given you something that would in turn persist you into giving me something back negatively. I do again apologize as it was and is not my intent.

This is what I have come up with thus far, but imo I feel much of it is monotonous.

#include <Array.au3>
#include <String.au3>

Local $v_lines = _RegExEng(BinaryToString(_sampData()))
msgbox(0, 'Return Virtual Lines', 'Virtual Lines in Returned Array : '& $v_lines[0] & @CRLF)


Func _RegExEng($sdat)
    Local $larr[1]
    $slen = StringLen($sdat)
    $nlin = 0
    $y = 1
    
    For $x = 1 to $slen
        $clstr = StringLeft($sdat, $x)
        $chr = StringTrimLeft($clstr, $x - 1)
        
        If $chr = @LF then
            $nlin = $nlin + 1
            $nchr = $x - $nlin * 2
            
            If $nlin = '1' then
            $clstr = $clstr
            elseIf $nlin > 4 then
            $clstr = StringStripWS( _
                   StringTrimLeft($clstr, $lnchr + $nlin + $y), 1)
                   $y = $y + 1
            else
            $clstr = StringStripWS( _
                   StringTrimLeft($clstr, $lnchr + $nlin), 1)
            EndIf
        
            If $nlin = '1' then
            $cstn = $nchr
            else
            $cstn = $nchr - $cstn
            EndIf
            
            ReDim $larr[$nlin]
            $larr[0] = $nlin
            _ArrayAdd($larr, $clstr)
            
            $sstrn = StringSplit($clstr, ' ')
            
            ; debug vars
            msgbox(0, '', _
            'Current Line Number    : ' & $nlin & @CRLF & _
            'Current String                 : ' & $clstr & _
            'Total Chars in String      : ' & $cstn & @CRLF & _
            'Number of Chars Read  : ' & $nchr & @CRLF & _
            'Number of Sub Strings  : ' & $sstrn[0] & @CRLF & @CRLF)
            
            $lnchr = $nchr
            $cstn = $nchr
        EndIf

    Next
    Return($larr)
EndFunc

Func _sampData()
Return( _
'0x48656C6C6F20506C616E65740D0A576F726C64206F72646572206973206F76657272617465640D0A53616C6C7920' & _
'73656C6C73207365617368656C6C7320646F776E206279207468652073656173686F726520626563617573652E2E2E' & _
'0D0A2E2E2E53616C6C7920697320616E20756E656D706C6F796564206869707069652E0D0A' _
)
EndFunc
Edited by UnKnOwned
Link to comment
Share on other sites

  • Solution

What's wrong with this?

#include <Array.au3>

Local $sData = BinaryToString(_Data())
Local $aSRE = StringRegExp('Count' & @CRLF & $sData, '([^\r\n]*)(?:\r\n|\n|\r)(?:[\r\n]$)?', 3)
$aSRE[0] = UBound($aSRE) - 1
_ArrayDisplay($aSRE)

Func _Data()
    Return '0x48656C6C6F20506C616E65740D0A576F726C64206F72646572206973206F76657272617465640D0A53616C6C7920' & _
            '73656C6C73207365617368656C6C7320646F776E206279207468652073656173686F726520626563617573652E2E2E' & _
            '0D0A2E2E2E53616C6C7920697320616E20756E656D706C6F796564206869707069652E0D0A'
EndFunc   ;==>_Data

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@gunniess

There is nothing wrong with that. Thank you for reminding me about splitting lines @LF @CR and what have you.

Is there any benefit in using one method over another.

#include <Array.au3>

$exRet = _GetLine()
_ArrayDisplay($exRet)

Func _GetLine()
$exStr = StringSplit(BinaryToString(_Data()), @LF)
$exStr[0] = UBound($exStr) - 1
Return($exStr)
EndFunc

Func _Data()
Return( _
'0x48656C6C6F20506C616E65740D0A576F726C64206F72646572206973206F76657272617465640D0A53616C6C7920' & _
'73656C6C73207365617368656C6C7320646F776E206279207468652073656173686F726520626563617573652E2E2E' & _
'0D0A2E2E2E53616C6C7920697320616E20756E656D706C6F796564206869707069652E0D0A' _
)
EndFunc
Link to comment
Share on other sites

You don't need to use UBound with StringSplit and the default parameter. My version is better in that if the EOL ends with @LF or @CRLF or @CR, then it doesn't matter. But your version assumes every EOL is @LF.

#include <Array.au3>

Local $sData = BinaryToString(_Data())
; Local $aSRE = StringRegExp('Count' & @CRLF & $sData, '([^\r\n]*)(?:\r\n|\n|\r)(?:[\r\n]$)?', 3)
; $aSRE[0] = UBound($aSRE) - 1
; _ArrayDisplay($aSRE)

Local $aSplit = StringSplit($sData, @LF) ; Notice this returns 5 instead of 4 like mine.
_ArrayDisplay($aSplit)

Func _Data()
    Return '0x48656C6C6F20506C616E65740D0A576F726C64206F72646572206973206F76657272617465640D0A53616C6C7920' & _
            '73656C6C73207365617368656C6C7320646F776E206279207468652073656173686F726520626563617573652E2E2E' & _
            '0D0A2E2E2E53616C6C7920697320616E20756E656D706C6F796564206869707069652E0D0A'
EndFunc   ;==>_Data

Of course there is a regular expression to convert EOL to one format by Melba23, but then it's a regular expression so it seems silly killing two birds with two stones, when mine does it with one.

; By Melba23, convert @CR & @LF to @CRLF. Using lookarounds, very clever! Modified by guinness.
$sReturn = StringRegExpReplace($sReturn, '((?<!\r)\n|\r(?!\n))', @CRLF)

Also, I wasn't offended last night, but you have to understand new users come along and want FREE code with no effort from their part. Before I used to give code away, but learnt the hard way that they weren't prepared to learn. When you posted your code that's when I knew your level of AutoIt and your willingness to learn. My advice is when posting a question at least try something, even if it doesn't work, showing us gives us an idea that you have an interest in AutoIt.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@guinness

This seems a more dignified place to start and for us to end this session on. I can understand completely reluctance on your part and without knowing me my internet words can come across a bit trite at times. That mixed with some lazy mindsets can create a disposition non to friendly from the receiving end. Actions will always speak louder than words so it would do me no good in stating that I intend on sticking around for awhile, but I do as long as I am welcome.

I was going to send this note of gratitude to you in a PM as it seems best to leave a topic where it was started, "on topic" and ending on a perfect note which you have done so on, "solved". Thank you again for that. I then remembered that prefixing every Google search query with the word "Autoit" 98% of the time leads you to this forum. Between Autoit search queries, included compiled help files with miles of endless guidance, and these forums. The only thing holding anyone back from obtaining an overwhelming abundance of Autoit knowledge would indeed be "THEMSELVES".

There is an entire world of knowledge at your finger tips, and anything that is not therefor retained, resides a personal flash drive for the brain. "THE INTERNET" It can be painstaking and time consuming to be a do it yourself-er, but it is much more rewarding in the end. Create a problem for yourself spend half your life figuring out the solution only to realize it consisted of two farts and a yawn, receive no recognition for efforts and I say friend, welcome to the real world.

On a more personal note visit my profile page if you care to know the seriousness of this user. I am not here to spam so I will only say it would take but a min to dig up the answer to that initial question. Up until now using Autoit has only been for personal needs not having to apply theories of "Good Coding Practices" or knowing if there is a cleaner easier way to do what was wanted or if what was wanted could even be done with this language. Coding is therapeutic, coding poorly is rigorous. Now the interest has turned to something a little more educational and public. Compared to the other languages I have fiddled with over the years Autoit has a very short learning curve even for a novice programmer which makes for a powerful teaching aid into the introduction of programming logic and methodology.

I've started noticing around these forums some of the more seasoned developers dabbling around with objects, memory, assembly, and some other very interesting projects not common to the scripting world. It sparked curiosity that some of these task could be completed with Autoit, interesting. I remember the source from way back when but am no longer current. I don't mind posting progress and examples of mismanaged script code that is full of errors, and some unintentional memory leaks to show willingness. If you stand naked in the rain surely eventually someone will give you some clothes or in this case lend.

I hope that these words have been well received as their intent was to inform as well as introduce as I am sure it is all my pleasure. Again I thank you for your assistance on this question and look forward to the future.

Link to comment
Share on other sites

No harm done at all. Thanks for taking the time to explain. As this topic is now solved, you can select the post that helped you and click the button 'mark solved'.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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