[Q] string alg to remove spaces

Looking at string algorithms and cannot figure what combination of them I need to remove all, but one spaces between words in a string so that "1 2 3" becomes "1 2 3" if there is a 'collection' of snippets for string alg, please let me know (I actually like that PHP has zillion of functions on strings, instead of having users to figure out the clever uses of 2 or 3 function for everything like in PERL) thanks in advance, Vlad -- V S P toreason@fastmail.fm -- http://www.fastmail.fm - IMAP accessible web-mail

2009/3/27 V S P
Looking at string algorithms and cannot figure what combination of them I need to
remove all, but one spaces between words in a string so that "1 2 3" becomes "1 2 3"
Sounds like you might need a regular expression to find sequences of multiple spaces. The algorithms "replace_all_regex" or "replace_all_regex_copy" should do what you want. e.g. string input = "1 2 3"; string output = replace_all_regex_copy(input, regex(" +"), " "); // output should be "1 2 3" where " +" is a regular expression to find sequences of 1 or more spaces. Regards Alex
participants (2)
-
Alex MDC
-
V S P