From e92064437d78f4e292c5a048aabcd793c742df39 Mon Sep 17 00:00:00 2001 From: Joseph Botosh Date: Sat, 5 Sep 2015 16:49:02 +0300 Subject: add function strip() to script functions --- npc/functions/main.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/npc/functions/main.txt b/npc/functions/main.txt index 27335371..9ca373cb 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -1,6 +1,7 @@ // Evol functions. // Authors: // 4144 +// Travolta // Description: // Build in functions. @@ -50,3 +51,27 @@ function script addremovemapmask { setmapmask getarg(0), (getmapmask(getarg(0)) | (getarg(1) + getarg(2))) ^ getarg(2); return; } + +// remove spaces at the start and end of string and return result +function script strip { + .@s$ = getarg(0); + if (.@s$ == "") + return ""; + .@start = 0; + .@end = getstrlen(.@s$) - 1; + for (.@i = .@start; .@i < .@end; .@i++) + { + if (charat(.@s$, .@i) != " ") + break; + else + .@start++; + } + for (.@i = .@end; .@i >= .@start; .@i--) + { + if (charat(.@s$, .@i) != " ") + break; + else + .@end--; + } + return substr(.@s$, .@start, .@end); +} -- cgit v1.2.3-70-g09d2