Sign in to follow this  
Followers 0
karliky

String to array

6 posts in this topic

#1 ·  Posted (edited)

I want to make string to array, i have this code:

$sString = "717D0500596F544645045141580FDB460000000063447143000000009001000001000000707D05002F6E5446E9915141




860EDB4600000000536BF9420000000090010000020000008D7D0500AB3E5446000084425671D94600000000000000000000




00009001000003000000727D05009D6B54467FEB5D415010DB4600000000062F8F43000000009001000004000000667D0500




AB2654460000804256FDDA4600000000020C8143000000009001000004000000677D0500AB9E534600008042567FDA460000




0000A8F41B43000000009001000004000000687D0500AB7E53460000804256EBDA460000000082FC8C430000000090010000




04000000647D0500"
$sTemp = StringTrimRight(StringRegExpReplace($sString, ".{8}", "\0 "), 1)
MsgBox(0, 0, $sTemp)

the result is splited by spaces:

717D0500 596F5446 45045141 580FDB46 00000000 63447143 00000000 90010000 01000000 707D0500 2F6E5446 E9915141 860EDB46 00000000 536BF942 00000000 90010000 02000000 8D7D0500 AB3E5446 00008442 5671D946 00000000 00000000 00000000 90010000 03000000 727D0500 9D6B5446 7FEB5D41 5010DB46 00000000 062F8F43 00000000 90010000 04000000 667D0500 AB265446 00008042 56FDDA46 00000000 020C8143 00000000 90010000 04000000 677D0500 AB9E5346 00008042 567FDA46 00000000 A8F41B43 00000000 90010000 04000000 687D0500 AB7E5346 00008042 56EBDA46 00000000 82FC8C43 00000000 90010000 04000000 647D0500

i need this,:

$sTemp[0] ;717D0500

$sTemp[1] ;596F5446

$sTemp[2] ;45045141

$sTemp[3] ;580FDB46

$sTemp[4] ;00000000 ......

Edited by karliky

Share this post


Link to post
Share on other sites



a function that splits a string into sections

$i_num is how large the sections should be, in your case it should be 8

returns a array where [0] is number of elemnts in the array and [1] is the first section.

Func _StringSplitSection($s_String, $i_num)
    Local $s_ret_string
    While StringLen($s_String) > 0
        $s_ret_string &= StringMid($s_String, 1, $i_num) & Chr(1)
        $s_String = StringTrimLeft($s_String, $i_num)
    WEnd
    
    $s_ret_string = StringTrimRight($s_ret_string, 1)
    Return StringSplit($s_ret_string, Chr(1))
EndFunc

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

a function that splits a string into sections

$i_num is how large the sections should be, in your case it should be 8

returns a array where [0] is number of elemnts in the array and [1] is the first section.

Func _StringSplitSection($s_String, $i_num)
    Local $s_ret_string
    While StringLen($s_String) > 0
        $s_ret_string &= StringMid($s_String, 1, $i_num) & Chr(1)
        $s_String = StringTrimLeft($s_String, $i_num)
    WEnd
    
    $s_ret_string = StringTrimRight($s_ret_string, 1)
    Return StringSplit($s_ret_string, Chr(1))
EndFunc
and how can i access to the result?

$sString = "717D0500596F544645045141580FDB460000000063447143000000009001000001000000707D05002F6E5446E9915141

860EDB4600000000536BF9420000000090010000020000008D7D0500AB3E5446000084425671D94600000000000000000000

00009001000003000000727D05009D6B54467FEB5D415010DB4600000000062F8F43000000009001000004000000667D0500

AB2654460000804256FDDA4600000000020C8143000000009001000004000000677D0500AB9E534600008042567FDA460000

0000A8F41B43000000009001000004000000687D0500AB7E53460000804256EBDA460000000082FC8C430000000090010000

04000000647D0500"

Func _StringSplitSection($s_String, $i_num)
    Local $s_ret_string
    While StringLen($s_String) > 0
        $s_ret_string &= StringMid($s_String, 1, $i_num) & Chr(1)
        $s_String = StringTrimLeft($s_String, $i_num)
    WEnd
   
    $s_ret_string = StringTrimRight($s_ret_string, 1)
    Return StringSplit($s_ret_string, Chr(1))
EndFunc

MsgBox(0, 0, _StringSplitSection($sString,8))
Edited by karliky

Share this post


Link to post
Share on other sites

$sString = "717D0500596F544645045141580FDB460000000063447143000000009001000001000000707D05002F6E5446E9915141


860EDB4600000000536BF9420000000090010000020000008D7D0500AB3E5446000084425671D94600000000000000000000


00009001000003000000727D05009D6B54467FEB5D415010DB4600000000062F8F43000000009001000004000000667D0500


AB2654460000804256FDDA4600000000020C8143000000009001000004000000677D0500AB9E534600008042567FDA460000


0000A8F41B43000000009001000004000000687D0500AB7E53460000804256EBDA460000000082FC8C430000000090010000


04000000647D0500"

Func _StringSplitSection($s_String, $i_num)
    Local $s_ret_string
    While StringLen($s_String) > 0
        $s_ret_string &= StringMid($s_String, 1, $i_num) & Chr(1)
        $s_String = StringTrimLeft($s_String, $i_num)
    WEnd
   
    $s_ret_string = StringTrimRight($s_ret_string, 1)
    Return StringSplit($s_ret_string, Chr(1))
EndFunc

$Data =  _StringSplitSection($sString,8)
For $x = 1 to  $Data[0]
    Msgbox(0, $x, $Data[$x])
Next


[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I want to make string to array, i have this code:

$sString = "717D0500596F544645045141580FDB460000000063447143000000009001000001000000707D05002F6E5446E9915141






860EDB4600000000536BF9420000000090010000020000008D7D0500AB3E5446000084425671D94600000000000000000000






00009001000003000000727D05009D6B54467FEB5D415010DB4600000000062F8F43000000009001000004000000667D0500






AB2654460000804256FDDA4600000000020C8143000000009001000004000000677D0500AB9E534600008042567FDA460000






0000A8F41B43000000009001000004000000687D0500AB7E53460000804256EBDA460000000082FC8C430000000090010000






04000000647D0500"
$sTemp = StringTrimRight(StringRegExpReplace($sString, ".{8}", "\0 "), 1)
MsgBox(0, 0, $sTemp)

the result is splited by spaces:

717D0500 596F5446 45045141 580FDB46 00000000 63447143 00000000 90010000 01000000 707D0500 2F6E5446 E9915141 860EDB46 00000000 536BF942 00000000 90010000 02000000 8D7D0500 AB3E5446 00008442 5671D946 00000000 00000000 00000000 90010000 03000000 727D0500 9D6B5446 7FEB5D41 5010DB46 00000000 062F8F43 00000000 90010000 04000000 667D0500 AB265446 00008042 56FDDA46 00000000 020C8143 00000000 90010000 04000000 677D0500 AB9E5346 00008042 567FDA46 00000000 A8F41B43 00000000 90010000 04000000 687D0500 AB7E5346 00008042 56EBDA46 00000000 82FC8C43 00000000 90010000 04000000 647D0500

i need this,:

$sTemp[0] ;717D0500

$sTemp[1] ;596F5446

$sTemp[2] ;45045141

$sTemp[3] ;580FDB46

$sTemp[4] ;00000000 ......

You were close:
#include <array.au3>
Local $s_string = _
    "717D0500596F544645045141580FDB460000000063447143000000" & _
    "009001000001000000707D05002F6E5446E9915141860EDB460000" & _
    "0000536BF9420000000090010000020000008D7D0500AB3E544600" & _
    "0084425671D9460000000000000000000000009001000003000000" & _
    "727D05009D6B54467FEB5D415010DB4600000000062F8F43000000" & _
    "009001000004000000667D0500AB2654460000804256FDDA460000" & _
    "0000020C8143000000009001000004000000677D0500AB9E534600" & _
    "008042567FDA4600000000A8F41B43000000009001000004000000" & _
    "687D0500AB7E53460000804256EBDA460000000082FC8C43000000" & _
    "009001000004000000647D0500"
    
Local $a_sre = StringRegExp($s_string, ".{8}", 3)
_ArrayDisplay($a_sre)
Edited by SmOke_N
Fixed word wrap

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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0