Jump to content

String to Array


jinred
 Share

Recommended Posts

Hi

I would like to load string from file into array, but i cant use StringSplit couse i haven't delimeter. My temp.txt contains C1B1F300 string, so with simple code:

$File = FileOpen("C:\temp.txt", 1)
$Read = String(FileRead('C:\temp.txt'))
FileClose($File)

i can load string, but how to load it into array to get result:

$Read[0]=C1

$Read[1]=B1

$Read[2]=F3

$Read[3]=00

Thanks for any help!

Link to comment
Share on other sites

  • Moderators

I don't see where you even attempted to try to do it... But it was easy enough:

$sString = "C1B1F300"
$aArray = _SplitByChar($sString, 2)
Func _SplitByChar($sString, $nChars)
    Local $sHoldReturn = ''
    For $iCC = 1 To StringLen($sString) Step $nChars
        $sHoldReturn &= StringMid($sString, $iCC, $nChars) & Chr(1)
    Next
    If $sHoldReturn Then Return StringSplit(StringTrimRight($sHoldReturn, 1), Chr(1))
    Return SetError(1, 0, '')
EndFuncoÝ÷ ØGb´êâ*.Á©í¶è­²+µ©Ý²)©æ®¶­sbb33c·57G&ærÒgV÷C´3#c3gV÷C°¢b33c¶'&Òõ7ÆD'6%5$Rb33c·57G&ærÂ"¥ô'&F7Æb33c¶'&Âb33²b33² ¤gVæ2õ7ÆD'6%5$Rb33c·57G&ærÂb33c¶ä6'2 &WGW&â7G&æu&VtWb33c·57G&ærÂb33²ç²b33²fײb33c¶ä6'2fײb33·Òb33²Â2¤VæDgVæ0

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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