/*
Title: Trim Whitespace
Credit to: CaptFalcon33035
Contributed by: CaptFalcon33035
This little snippet can be used to trim whitespace off of the beginning and
the end of a string. It's simple enough to use--the string is passed as the
first parameter and the method is passed as the second. The method can be
one of three values--HEADING_WHITESPACE, TRAILING_WHITESPACE, or default
HEADING_WHITESPACE|TRAILING_WHITESPACE, which means it will take the
whitespace from both sides of the string.
*/
#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
ID:195043
Oct 25 2008, 11:00 am
|
|
Aug 12 2009, 8:07 am (Edited on Aug 12 2009, 8:41 am)
|
|