String Manipulation

Help with the Ecere cross platform system functionality: working with files, threads, timers, databases, etc.
Post Reply
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

String Manipulation

Post by redj »

Hi all,

Let's ask and answer questions about string manipulation in eC/EcereSDK here.

-redj
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

Re: String Manipulation

Post by redj »

What's the best method to get rid of extra spaces in a string?

Please show method(s) to remove double, triple and so on space by a single space.
Including solution(s) that handle all space characters including tab or alternatively only actual spaces.

-redj
redj
Posts: 105
Joined: Sun Jan 17, 2010 10:03 am

Re: String Manipulation

Post by redj »

here's something:

sdk/extras/stringTools.ec

that works rather nicely:

Code: Select all

char * s = SingleFuncCharsCopy(" my    string   ", isspace, both, ' ');
also:

Code: Select all

char * s = SingleCharsCopy(" my    string   ", " \t\n\r!@#$%^&*()-=+{}[]|", both, ' ');
list of new functions:

Code: Select all

void SingleChars(char * string, char * output, char * chars, Trim trim, char alt)
char * SingleCharsCopy(char * string, char * chars, Trim trim, char alt)
void SingleFuncChars(char * string, char * output, int (*CharTest)(char), Trim trim, char alt)
char * SingleFuncCharsCopy(char * string, int (*CharTest)(char), Trim trim, char alt)
Enjoy!

-redj
Post Reply