Hello! Not so long ago, I tried to write a script that would remove extra spaces in the players' sentences, so that's what I did:
It is work, but i would like to know what can be optimized or improved.
Thanks, that's what i got:
PHP Code:
new i = strlen(text), spaces;
while(--i != -1)
{
switch(text[i])
{
case ' ':
{
spaces++;
if(spaces > 1)
{
spaces--;
strdel(text, i, i+1);
}
}
default: spaces = 0;
}
}
if(text[i-1] == ' ') strdel(text, i-1, i);
if(text[0] == ' ') strdel(text, 0, 1);
Thanks, that's what i got:
PHP Code:
DeSpace(string[], i = 0)
{
while((i = strfind(string, " ", _, i)) != -1) strdel(string, i, i + 1);
if(string[0] == ' ') strdel(string, 0, 1);
if(string[strlen(string)-1] == ' ') strdel(string, strlen(string)-1, strlen(string));
return string[strlen(string)];
}
![[Image: aWbv5wm.gif]](https://imgur.com/aWbv5wm.gif)