Standard trim, rtrim, and ltrim functions to remove leading and trailing whitespace characters.
Language:
Dark Basic Pro
Code:
function trim(str as string) str = rtrim(ltrim(str)) endfunction str function ltrim(str as string) local char as dword local length as dword length = len(str) repeat inc char if asc(mid$(str, char)) <> 9 and asc(mid$(str, char)) <> 32 str = right$(str, length - char + 1) exit endif until char > length endfunction str function rtrim(str as string) local char as dword local length as dword length = len(str) char = length repeat if asc(mid$(str, char)) <> 9 and asc(mid$(str, char)) <> 32 str = left$(str, char) exit endif dec char until char = 0 endfunction str
(3 votes)
Sat, 06/09/2007 - 00:24
Very useful - surprised they're not in "core" of DBP!
Mon, 07/02/2007 - 21:43
nice work :~)