Jump to content

StringSplit with array issue.


clearguy
 Share

Recommended Posts

Hi,

my script:

$b='a,b,c,d,e,f-a1,b1,c1,d1,f1'
$b=StringSplit($b,'-')
Dim $a[2]
For $i=1 To $b[0]
    $a[$i-1]=StringSplit($b[$i],',')
Next
Dim $c=$a[1][3]
MsgBox('',0,$c)

It says:Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Doesn't the StringSplit() make a simple array 2dimensional?

Link to comment
Share on other sites

$b='a,b,c,d,e,f-a1,b1,c1,d1,f1'
$b=StringSplit($b,'-')
Dim $a[2]
For $i=1 To $b[0]
    $a[$i-1]=StringSplit($b[$i],',')
Next
Dim $c=$a[1][3]
MsgBox('',0,$c)oÝ÷ Ø:²}ý¶Ø^JÚâ©+fjG²)©æ«­¬¶v)Ȩ©ªê-^.Ê'ò¢êÞiܨº·(u쨻¥Ç¶®º+jëh×6Dim $a[2] ; <=== THIS IS AN ONE-DIMENSIONAL ARRAY !!
Dim $c=$a[1][3]; <== YOU TRY TO ACCESS A DIMENSION THAT DOES NOT EXIST !!

You do it right with $b but wrong with $a.....

BTW: And no, StringSplit() returns not a 2-dim-array! See help file.

Return Value

Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.

If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1]).

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • Moderators

Hi,

my script:

$b='a,b,c,d,e,f-a1,b1,c1,d1,f1'
$b=StringSplit($b,'-')
Dim $a[2]
For $i=1 To $b[0]
    $a[$i-1]=StringSplit($b[$i],',')
Next
Dim $c=$a[1][3]
MsgBox('',0,$c)oÝ÷ Ølk+¢Z+ QtÓM,¥©ì·)^
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

clearguy, if you read your code you will see the error.

Dim $a[2] ; <=== THIS IS AN ONE-DIMENSIONAL ARRAY !!
Dim $c=$a[1][3]; <== YOU TRY TO ACCESS A DIMENSION THAT DOES NOT EXIST !!
oÝ÷ Ù.v­®(!·­Múm»­Âº'­MúhÖwg¡+kx¦X­­ën®{'¢Ö¶v)®¶²ßtz¥¥ø¥z$^¶êçU©ny­º¹ìjv«­¬­çâ®Ë^éÝ7éªëk-¢{Z{-éî·«¡û-®)ಷ­º¹ÞvØ^­éx§é^éí³MújºÚË]7éªëk-µÇ(Ö¢Ø^uéb+^vËkx,!ùèuéb+^®Ì­çèºw^®º+˶Ú5¶¢éíÍtߦ«­¬´jwmçî[-®)àÊÞ¶êçyÝ7éªëk-(^z»
º»ªê-xéÈ!jxvØ^Ó~jºÚÊÚ®(!µØ¦z{"¢ybëaÆ®¶­sbb33c¶#Òb33¶Æ"Æ2ÆBÆRÆbÖÆ#Æ3ÆCÆcb33°¢b33c¶#Õ7G&æu7ÆBb33c¶"Âb33²Òb33²¤FÒb33c¶³Õ³Ð£´f÷"b33c¶ÓFò¢b33c¶³Õ³ÓÕ7G&æu7ÆBb33c¶%³%ÒÂb33²Âb33²£´æW@¤FÒb33c¶3Òb33c¶³Õ³Ð¤×6t&÷b33²b33²ÃÂb33c¶2oÝ÷ Ø­¶§!Ú'ßÛd!£hëZÖÛÖÜÕúèMúkM*º^©
Your works fine, I'm trying to understand it, thanks ;) . Edited by clearguy
Link to comment
Share on other sites

Okay I changed the $a array to a right dimension like this:

$b='a,b,c,d,e,f-a1,b1,c1,d1,f1'
$b=StringSplit($b,'-')
Dim $a[1][1]
;For $i=0 To 1
    $a[0][0]=StringSplit($b[2],',')
;Next
Dim $c=$a[0][0]
MsgBox('',0,$c)oÝ÷ Ø­¶§!Ú'ßÛd!£hëZÖÛÖÜÕúèMúkM?ªê-{¢µ©¨éíN«z+,¢g­)àªê-²ÚÚªº`¢)à¢r7öYaj÷­¡È^rKajÔ^
^jëh×6#include <array.au3>

$text='a,b,c,d,e,f-a1,b1,c1,d1,f1'
$b=StringSplit($text,'-')

Dim $a[2]
For $i=1 To $b[0]
    $a[$i-1]=StringSplit($b[$i],',')
Next
_ArrayDisplay($a[0],"A[0]")
_ArrayDisplay($a[1],"A[1]")

$c=$a[0][3]
MsgBox('',0,$c)

EDIT: I created a bug report: http://www.autoitscript.com/forum/index.php?showtopic=36908

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Yes it is that what I don't understand.

Even if it works with $c=$a[0] (in bug report topic) ... it doesn't matter anything because I can do it in assigning the content of StringSplit to another variable,I would not spend my time to reassign StringSplit to an array indeed ;) But I need to get it in an array.

Edited by clearguy
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...