Passing Values to Roster via pff

Discussions about creating CAPI applications to run on Android devices
Post Reply
amari
Posts: 22
Joined: February 24th, 2024, 11:29 am

Passing Values to Roster via pff

Post by amari »

I need to pass list of names to CSEntry,via pff I wanna pass the number of items in the roster and names too,
How can assign names inside CSEntry, when I pass array to CSEntry It capture it as array, so how to split it in to array
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Passing Values to Roster via pff

Post by Gregory Martin »

The current CSPro logic functions don't make it easy to split a string by a delimiter, but you can use a user-defined function to convert a list (or array) into a single string, and then convert it back. These functions use a unlikely-to-be-used delimiter, but you could change that character if ╳ doesn't suit your needs.
function string ListToString(List string sl, string delimiter = '╳')

    string text;
   
    do numeric ctr = 1 while ctr <= sl.length()
       
        // add a delimiter between each list entry
       
if ctr > 1 then
           
text = text + delimiter;
        endif;
       
        text = text + sl(ctr);

    enddo;
   
    exit text;

end;


function StringToList(List string sl, string text, string delimiter = '╳')

    sl.clear();
   
    numeric text_length = length(text);
   
    // quit out if the string is empty
   
if text_length = 0 then
        exit
;
    endif;
   
    numeric next_string_start_pos = 1;
   
    do numeric ctr = 1 while ctr <= text_length
   
        // if the character is a delimiter, add the text preceeding it
       
if text[ctr:1] = delimiter then
           
sl.add(text[next_string_start_pos : (ctr - next_string_start_pos)]);
            next_string_start_pos = ctr + 1;
        endif;
   
    enddo;
   
    // add the last entry
   
sl.add(text[next_string_start_pos]);

end;
Post Reply