Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

String Manipulation
http://ec-lang.org/community/viewtopic.php?f=9&t=342
Page 1 of 1
Author:  redj [ Sat Dec 15, 2012 7:52 pm ]
Post subject:  String Manipulation

Hi all,

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

-redj
Author:  redj [ Sat Dec 15, 2012 7:56 pm ]
Post subject:  Re: String Manipulation

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
Author:  redj [ Sun Dec 16, 2012 2:41 am ]
Post subject:  Re: String Manipulation

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
All times are UTC-05:00 Page 1 of 1