xmen Posted May 4, 2005 Posted May 4, 2005 Pls explain why array1[0] = /0? but not array1[12] = /0 #include <String.au3> #include <Array.au3> dim $array1[12] $string = "hello world" for $i = 0 to Stringlen ($string) step 1 $array1[$i] = StringMid ($string, $i, 1) next _ArrayDisplay($array1, "test")
therks Posted May 4, 2005 Posted May 4, 2005 I'm not sure if this is the answer you're looking for, but...StringMid starts at 1.This means that StringMid($string, 1, 1) will return "h"StringMid($string, 0, 1) will error I believe, and return an empty string.If you wanted to put the string into an array in the manner you're demonstrating here, you must alter your code slightly, as such:#include <Array.au3> dim $array1[12] $string = "hello world" for $i = 0 to Stringlen ($string) - 1 $array1[$i] = StringMid ($string, $i + 1, 1) next _ArrayDisplay($array1, "test")Note: You did not need to include "String.au3" for this code snippet, so I removed it. StringLen, StringMid, etc, are native functions to AutoIt.Note 2: It would be less code if you don't mind using the StringSplit function.$string = "hello world" $array = StringSplit($string, '') _ArrayDisplay($array, "test") My AutoIt Stuff | My Github
xmen Posted May 4, 2005 Author Posted May 4, 2005 oh, i made the mistake, not /0, but a empty string. Thanks the explain.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now