Delete a character from a string

Discussions about CSEntry
Post Reply
abdou-xb-93
Posts: 1
Joined: January 14th, 2025, 2:49 am

Delete a character from a string

Post 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
Hydro-abdou
Gregory Martin
Posts: 1860
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Delete a character from a string

Post 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;
Post Reply