Trim Whitespace in Tutorials & Snippets
|
|
#define HEADING_WHITESPACE 1 #define TRAILING_WHITESPACE 2
proc/TrimWhitespace(var/string, var/method=HEADING_WHITESPACE|TRAILING_WHITESPACE) if(!string || !istext(string) || !method || isnum(method)) return string var/char = 1 var/currentChar if(method & HEADING_WHITESPACE) char = 1 currentChar = copytext(string, char, char+1) while(currentChar && (currentChar <= " ")) char ++ currentChar = copytext(string, char, char+1) string = copytext(string, char) if(method & TRAILING_WHITESPACE) char = lentext(string) currentChar = copytext(string, char, char+1) while(currentChar && (currentChar <= " ")) char -- currentChar = copytext(string, char, char+1) string = copytext(string, 1, char+1) return string
|
|