SphereCommunity
Spaces - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: Spaces (/Thread-Spaces)



Spaces - Runcuks - 12-04-2013 10:47 PM

Hi, could someone tell me how to players to use spaces when they choose name for example " MyNickname" "MyNickname "
I came up with something like this but it didnt work

IF (STRMATCH(* *, <ARGTXT[0]>)) || (STRMATCH( *, <ARGTXT[0]>)) || (STRMATCH(* , <ARGTXT[0]>))
src.sysmessage @023 You can not use spaces.
return 1
ENDIF


RE: Spaces - Mordaunt - 12-04-2013 11:06 PM

Because you are comparing ARGTXT against.... nothing.

http://wiki.sphere.torfo.org/index.php/Chapter_10


If you refer to the link I have posted, you'll find a few methods, inclusing STRPOS which can be used to find spaces in a string.
You should be able to do it with STREGEX also using <ch 32> to detect spaces (I think... haven't run a test to make sure)


RE: Spaces - Khaos - 12-04-2013 11:29 PM

This possibly might work.
PHP Code:
if strmatch("* *","<src.name>")
 
src.smsg You cannot use spaces in your name
endif
return 


Try removing the quotes if it gives you an issue.


RE: Spaces - Runcuks - 12-04-2013 11:55 PM

(12-04-2013 11:29 PM)Khaos Wrote:  This possibly might work.
PHP Code:
if strmatch("* *","<src.name>")
 
src.smsg You cannot use spaces in your name
endif
return 


Try removing the quotes if it gives you an issue.

Jup that worked thanks!


RE: Spaces - Khaos - 12-05-2013 01:01 AM

You are quite welcome. Smile


RE: Spaces - Feeh - 12-05-2013 08:00 AM

What about STRTRIM? You can use it to remove spaces
http://wiki.sphere.torfo.org/index.php/Chapter_10#STRTRIM

if (STRMATCH(*32*,<asc <ARGTXT[0]>>))
SYSMESSAGE "No spaces allowed!"


RE: Spaces - XuN - 12-05-2013 09:06 AM

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