Jump to content

Recommended Posts

Posted

Hello everyone,

I was trying to store this string into my array: "Hamsters | Cute"

But after I store it, I used _ArrayDIsplay and it showed "Hamster" being on one row and "Cute" being on the row after it.

So it looks like the "|" symbol acts as a row seperator in an array.

My question is: Is there a way for my array to display "Hamsters | Cute" in 1 row ?

Thanks,

Brian

Posted (edited)

Hi BlazerV60

Can you post some of your script ?

Maybe try check autoit wiki http://www.autoitscript.com/wiki/Arrays

If im not wrong then you are using this :

Local $iMax
 
Local $data = "Element 1|Element 2|Element 3"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, "|")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

Try change "|" to "," and check stringsplit function : https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm

Local $iMax
 
Local $data = "Hamster | Cute,Array2 | Array2"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, ",")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf
Edited by ghost11996

[color=rgb(255,0,0);]C[/color][color=rgb(255,140,0);]a[/color][color=rgb(255,215,0);]n[/color] [color=rgb(255,255,0);]i[/color] [color=rgb(175,238,238);]e[/color][color=rgb(0,255,255);]a[/color][color=rgb(64,224,208);]t[/color] [color=rgb(0,0,205);]S[/color][color=rgb(0,0,255);]i[/color][color=rgb(0,0,128);]g[/color][color=rgb(75,0,130);]n[/color][color=rgb(128,0,128);]at[/color][color=rgb(238,130,238);]u[/color][color=rgb(221,160,221);]r[/color][color=rgb(230,230,250);]e[/color] [color=rgb(0,255,0);]?[/color] :ermm: [color=rgb(0,255,0);]Project: Mini Youtube BETA[/color]

Posted

  On 6/20/2014 at 5:19 AM, ghost11996 said:

 

Hi BlazerV60

Can you post some of your script ?

Maybe try check autoit wiki http://www.autoitscript.com/wiki/Arrays

If im not wrong then you are using this :

Local $iMax
 
Local $data = "Element 1|Element 2|Element 3"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, "|")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

Try change "|" to "," and check stringsplit function : https://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm

Local $iMax
 
Local $data = "Hamster | Cute,Array2 | Array2"
 
; The string in data will be split into an array everywhere | is encountered
Local $arr = StringSplit($data, ",")  
 
If IsArray($arr) Then 
    For $i = 1 to $arr[0]
        ConsoleWrite($arr[$i] & @LF)
    Next
EndIf

 Hi ghost

,

Thanks for responding! For certain reasons, I need the separator to be "|" and not a comma or any other symbol.

Here is what my code looks like:

#include <Array.au3>
#include <MsgBoxConstants.au3>

$Ham1 = "Hamster"
$Ham2 = "Cute"

Local $aArray_Base[2] = ["Org item 1", "Org item 2"]

_ArrayAdd($aArray_Base, $Ham1&"|"&$Ham2)
_ArrayDisplay($aArray_Base, "1D - Base array")
Posted

Did you read the help file for _ArrayAdd()? Change the $sDelim_Item to something other than |.

Ticket closed!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

If you avoid using _ArrayAdd() then you should not encounter such problems. It is best if you know the size of the array in advance, then you can simply assign values to the array elements as and when needed.

;

#include <Array.au3>

Local $aArray[3] ; 3 elements are needed

$aArray[0] = "Hamster"
$aArray[1] = "Cute"
$aArray[2] = $aArray[0] & "|" & $aArray[1]

_ArrayDisplay($aArray)

;

Also take a look at ReDim in the help file (for resizing arrays).

Edited by czardas
  • Moderators
  • Solution
Posted

BlazerV60,

See my posts >here and later in the same thread for more explanation. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

czardas,

Thanks for that. :thumbsup:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Using the OP's code in post #3 and assuming that the expected output is a 1D array - and using _ArrayAdd and its really nice improvement  :)

#include <Array.au3>

$Ham1 = "Hamster"
$Ham2 = "Cute"

Local $aArray_Base[2] = ["Org item 1", "Org item 2"]

_ArrayAdd($aArray_Base, $Ham1&"|"&$Ham2, 0, ";")
_ArrayDisplay($aArray_Base, "1D - Base array")

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
×
×
  • Create New...