Sign in to follow this  
Followers 0
hein008

How to save an array in a string?

8 posts in this topic

#1 ·  Posted (edited)

hey guys,

I want to save an array in a string, like in this example:

$array[0]=H

$array[1]=E

$array[2]=Y

$string = _function_i_search($array)

and then the string should be '123'

do you know what I mean? Is there any solution for this question? I already tried _arraydisplay() but that doesnt work well because the output is interrupted by enters.

I could say I search the reverse of stringsplit()

Edited by hein008

Share this post


Link to post
Share on other sites



Make your own function. You can use the '&' operator to concatenate strings.

And the last part of your post does not make sense. How do you start with HEY then end up with 123?

Did you read the help file?

Global $array[3]
$array[0] = "H"
$array[1] = "E"
$array[2] = "Y"
Global $string = ""
For $i = 0 To 2
    $string &= $array[$i]
Next
MsgBox(0x2000, "Output", $string)

Share this post


Link to post
Share on other sites

Make your own function. You can use the '&' operator to concatenate strings.

And the last part of your post does not make sense. How do you start with HEY then end up with 123?

Did you read the help file?

Global $array[3]
$array[0] = "H"
$array[1] = "E"
$array[2] = "Y"
Global $string = ""
For $i = 0 To 2
    $string &= $array[$i]
Next
MsgBox(0x2000, "Output", $string)

Here is my function. Pass in your array, what the delimeter should be, and what index in the array to start at.

Func StringConcat($array,$delim,$start)
    Local $i
    Local $string = ""

    For $i = $start to UBound($array) - 1
        If $i > $start Then
            $string = $string & $delim
        EndIf
        $string = $string & $array[$i]
    Next

    Return $string
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#Include <Array.au3>
_ArrayToString(Const ByRef $avArray [, $sDelim = "|" [, $iStart = 0 [, $iEnd = 0]]])

...or maybe not?

Edited by MrMitchell

Share this post


Link to post
Share on other sites

#Include <Array.au3>
_ArrayToString(Const ByRef $avArray [, $sDelim = "|" [, $iStart = 0 [, $iEnd = 0]]])

...or maybe not?

Pfft. Why would you want to use functions already written for you? ;)

Share this post


Link to post
Share on other sites

Why would you want to use functions already written for you?

ahah


[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

Share this post


Link to post
Share on other sites

Hi.

For what purpose do you want to concatenate an array to one, large string?

If the purpose is to save the string's content to a file: Use _FileWriteFromArray().

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Hi.

For what purpose do you want to concatenate an array to one, large string?

If the purpose is to save the string's content to a file: Use _FileWriteFromArray().

Regards, Rudi.

I have a script/program that can be a client or a server. The server mode manages multiple sets of information (including the contents of a listbox) in the registry using arrays concatenated into strings. When a client mode script connects to it via TCP, the server sends the information to the client as a single string also. The client parses and keeps temporary storage of the information in its own arrays and listbox, which it can then modify and send back to the server to update the data there.

I was just unaware of the function already built into the array include. Such is my typical learning path for a new programming language: learn syntax, write functions I can't find, find those functions in a separate library.

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