Jump to content

split your text in array example


Recommended Posts

hello evrybody
here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number

you have a long text and you want to split it in an array
that evry colum have a number (n) of lines
i made a function that do that for you
just call it with a three params
your text
the number that you want to put in each col
the siparator
default is "|"

here is the function with example

i hope that it will be useful for you


#include <Array.au3>
$s_txt = "some text1some text2|some text3|some text4|some text5|some text6"
$array = splitText($s_txt, 2)

Func splitText($s_text, $i_number, $s_siparator = "|")
    Local $a_TXT = StringSplit($s_text, $s_siparator)
    Local $a_Return[$a_TXT[0] + 1]
    If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then
        ReDim $a_Return[2]
        $a_Return[0] = 1
        $a_Return[1] = $s_text
        Return $a_Return
    Local $i_Processed = 1, $i_arrayProcessed = 1
        For $i = $i_Processed To ($i_Processed + $i_number) - 1
            If ($a_TXT[0] < $i) Then ExitLoop
            If Not ($a_Return[$i_arrayProcessed]) Then
                $a_Return[$i_arrayProcessed] = $a_TXT[$i]
                $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i]
            $i_Processed += 1
        $i_arrayProcessed += 1
    Until ($a_TXT[0] < $i_Processed)
    ReDim $a_Return[$i_arrayProcessed]
    $a_Return[0] = $i_arrayProcessed - 1
    Return $a_Return
EndFunc   ;==>splitText

accept my greetings

thanks to

for his notes

Edited by nacerbaaziz
updated code
Link to comment
Share on other sites


You can use the consolewrite to output into the console_

For $i = 1 To $array[0]
    ConsoleWrite  $i & "> " & $array[$i] & @crlf)

And you can use _ArrayDisplay to display the content of an array, 

it needs an #include <Array.au3> at the top and use


instead of the for next loop.


The description should be something like:

Split a string with a delimiter, with the ability to ignore every other delimiter with $i_number. 

(p.s. there is a bug if $i_number is 0 )

Edited by Dan_555

Some of my script sourcecode

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

  • Create New...