Jump to content

How to save an array in a string?


hein008
 Share

Recommended Posts

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
Link to comment
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)
Link to comment
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
Link to comment
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.

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...