Jump to content
Sign in to follow this  
xmen

array[0] = /0 ?

Recommended Posts

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")

Share this post


Link to post
Share on other sites

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")

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...