Page 1 of 1

Delete a character from a string

Posted: January 16th, 2025, 3:55 am
by abdou-xb-93
Hello
I would like to know how to delete a character from a string knowing that I have a loop that looks for a comma in the last character and deletes it.
example
string = a,b,c,d,e,f,,,,,,,
it becomes
new_string = a,b,c,d,e,f
when the loop finds that there is no comma in the last character, it stops
(input is not a multigroup, it's just a chekbox)
thank you very much

Re: Delete a character from a string

Posted: January 16th, 2025, 7:39 am
by Gregory Martin
I'm not sure if you're really posting about CSPro, but if so, you can do something like:
function string RemoveTrailingCommas(string text)

    // convert commas to spaces
   
do numeric ctr = length(strip(text)) while ctr >= 1 and text[ctr:1] = ',' by -1
       
text[ctr:1] = ' ';
    enddo;
   
    // return the trimmed string (to remove the added spaces)
   
exit strip(text);

end;