Re: Something like trim()
| From: | cybot | Date: | Fri, 31 Jan 2003 14:58:44 +0000 |
| Subject: | Re: Something like trim() | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-18272@lists.php.net to get a copy of this message | ||
is there no more complicated solution for this? ;-)
nothing for bad!
B.A.T. Svensson wrote:
Something like (not tested and compiled - please find the bugs :)) will remove white space dups: char *TrimInString(char *pzWashMe) { if (!pzWashMe) return NULL; register char *pzMarker = pzWashMe; bool bStillTrimingString = false; while (StrReplacee("\t", " ", pzMarkerrReplacee("\n", " ", pzMarker))-- Sebastian Mendel info@sebastianmendel.de www.sebastianmendel.de www.tekkno4u.de www.nofetish.com;; while (*pzMarker) { // loop 1 bool bStillTrimingString = false;while (*pzMarker && !isspace(*(pzMarker++)) // loop 2 ;;register int nIndex = 0; while (isspace(*(pzMarker+nIndex++)) { // loop 3 bStillTrimingString = true; }if (nIndex) { strcpy(pzMarker, (pzMarker + nIndex)); }} return pzMarker; } First it replace tabs and newlines with blank spaces, then the function will scann the string after a whitespace (loop 2). If it finds one. Then it will try to justify the hypothese H that this white space is followed by another white space (loop 3). If H is true it will count the number of whitepace, and then move the moving down data to just leave the first white space left. After that it falls into loop 1 again and check if we reach the end of the string or not, if not, we do all the things once again.-----Original Message----- From: Bobo Wieland [mailto:dev@elstudion.com] Sent: Thursday, January 30, 2003 8:26 AM To: php-windows@lists.php.net Subject: [PHP-WIN] Something like trim() Is there an easy way to get rid off white space characters in a string? Like trim() but for the whole string and leaving single white spaces as they arebut removing all occurences of '\t','\n' and ' '(leaving a single '')... I've tried the manual but couldn't find anything... . bobo . www.elstudion.com . www.elstudion.com/bobo . -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php