SphereCommunity
STRTRIM seems not to be working - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: STRTRIM seems not to be working (/Thread-STRTRIM-seems-not-to-be-working)



STRTRIM seems not to be working - kn4tseb - 08-08-2014 03:37 AM

using jul31 dev ....

im trying to eat the spaces in a text with strtrim but doesnt seem to work...

example

serv.log <strtrim whats up dude>

returned text log: whats up dude


RE: STRTRIM seems not to be working - darksun84 - 08-08-2014 03:40 AM

This function be used to strip all whitespace (spaces, tabs, newlines) from the start and end of a string. Tongue


RE: STRTRIM seems not to be working - Skul - 08-08-2014 03:49 AM

same result here on August 4th build, 2014.


RE: STRTRIM seems not to be working - kn4tseb - 08-08-2014 04:15 AM

good to know its not only me xD


RE: STRTRIM seems not to be working - darksun84 - 08-08-2014 04:21 AM

Trimming removes the white-spaces just in the beginning and end of the string, not in the middle and so on.. Big Grin


RE: STRTRIM seems not to be working - kn4tseb - 08-08-2014 04:48 AM

omg... so is it possible to remove whitespaces in middle of a string?

i guess its necessary some strsub and strlen or streat and strarg >.<


RE: STRTRIM seems not to be working - Skul - 08-08-2014 05:49 AM

Yes:
Code:
[function removespaces]
local.args=<args>
while !(strmatch(0,<local.args>)) && !(strmatch(00,<local.args>))
  local.return=<strarg <local.args>>
  local.args=<streat <local.args>>
endwhile
return <local.return>
load this script and type something like .show removespaces test test test. It should return 'testtesttest'.


RE: STRTRIM seems not to be working - XuN - 08-08-2014 07:09 AM

Taken from: http://forum.spherecommunity.net/Thread-Spaces
(12-05-2013 09:06 AM)XuN Wrote:  StrTrim only works for spaces at begin of given string, if you want to remove any spaces from the text they Input use <asciiremove 32,<argtxt[0]>>

Code:
[function asciiremove]
local.ascii=<argv[0]>        //Ascii Dec value of the character we want to remove, for detailed information and IDs look http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
local.text=<streat <args>>    //Text to remove <local.ascii>
local.check=<strpos 0 <dlocal.ascii> <args>>    //We check if we have any specified ascii chr to remove
while <local.check>>0    //If so we begin
    local.len=<eval STRLEN(<local.text>)>    //Length of the text
    local.pos=<strpos 0 <dlocal.ascii> <local.text>>    //Position of current ascii char found
    if (<local.pos>==0)    //If ascii is first char we make aditional IF to remove it
        local.text=<strsub <eval <local.pos>+1> <local.len> <local.text>>    //local.text=Text except first character
    else    //Otherwise we can do whole replacement with one line
        local.text=<strsub 0 <local.pos> <local.text>><strsub <eval <local.pos>+1> <local.len> <local.text>>    //Text until found charText from found char (without spaces nor anything)
    endif
    if (<strpos 0 <dlocal.ascii> <local.text>>==-1)    //We check if we have more ascii chars to remove
        local.check=0    //and we set to 0 if not, to stop while.
    endif    
endwhile
return <local.text>        //Fixed text



RE: STRTRIM seems not to be working - kn4tseb - 08-08-2014 07:15 AM

Thank you both! Smile