Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerBuilder - string to array convert

I have string in PowerBuilder:

string test_string = "1,2,3,4,5"

I want to convert it to array:

 string array[] = {'1','2','3','4','5'}

How to do that?

// Thanks for help :)

I do that:

    string string_to_edit = "1,2,3,4"
    string array[], string_now
    long arraylen, stringlen, place_nbr, i, place_tt

    stringlen = len(string_to_edit)
    DO WHILE  stringlen > 0 
        place_nbr = pos(string_to_edit, ",")
            IF place_nbr > 0 THEN
                place_tt = place_nbr - 1
                string_now = Mid(string_to_edit,0,place_tt)
                string_to_edit = RIGHT(string_to_edit,stringlen - place_nbr)
                stringlen = stringlen - place_nbr
            ELSE
                string_now = string_to_edit
                string_to_edit = RIGHT(string_to_edit,stringlen - place_nbr)
                stringlen = 0
            END IF
        string_now = trim(string_now)
        arraylen = UpperBound(array)
        array[arraylen+1] = string_now
    LOOP
like image 998
Piszu Avatar asked Nov 17 '25 20:11

Piszu


2 Answers

You can get inspiration by looking at the way that it's done in the PFC ( the of_parsetoarray() function) :

https://pfc.svn.codeplex.com/svn/12.0/pfcapsrv/pfc_n_cst_string.sru

like image 138
RealHowTo Avatar answered Nov 20 '25 18:11

RealHowTo


You may use any gettoken algorithm for strings. Arrays in PB grows automatically. For example

string array[]
array[UpperBound(array)+1] = NextToken(test_string,',')

Write NextToken function yourself, or loop with Pos(test_string, ',', iFrom)

like image 33
Maximus Avatar answered Nov 20 '25 17:11

Maximus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!