Clear Spaces

by Lugia319
Pesky spaces in chat? I can fix that!
ID:1447574
 
Update: Ter13 showed me that you can still input the tab character by copying it from charmap. I've added a fix so you can't spam tab to win.

It's not big, but it's useful.

I spent a lot of time looking for this, but I couldn't find anything that specifically handled this issue, so I made it myself.

Suppose you want to make a chat function
verb
Chat(T as text)
if(length(T) == 0) return
else
view(src) << "[src] says: [T]"


This offered NO protection against strings like this with large numbers of spaces.

So I fixed it. With my code;

var/String = ClearSpaces(T)
view(src) << "[src] says: [String]"

http://www.byond.com/forum/?post=195043

If the Snippets Database still existed in its organized form, I'm sure you would've found it easier. It doesn't have your "clear middle spaces" function, though.
In response to Kaiochao
You've just given an idea. While it's not exactly the most obvious for new members, there are search features, and topics for all the major resources, tutorials, etc. Snippets, though, are pretty scattered for the most part. So, maybe it would be a good idea for people to gather all of the best snippets into one post?
In the meantime, these are most (if not all) of the posts that were in Jtgibson's member forum, AKA the Snippets Database.

http://www.byond.com/ forum/?command=search&posts=1&scope=local&forum=22&text=%22c ontributed+by%22
Yes, in all honesty, there's just so much clutter that you can never really find what you want unless you know EXACTLY what it is or where it is. And if you're looking for something that you don't know exists, it get's troublesome.
Made this pretty fast, profiled all 3 with 1000 calls.

                      Profile results (average time)
Proc Name Self CPU Total CPU Real Time Calls
----------------------- --------- --------- --------- ---------
/mob/verb/Test_Lugia 0.007 0.634 0.634 1
/mob/verb/Test_Koz 0.004 0.087 0.087 1
/mob/verb/Test_Control 0.008 0.008 0.008 1
/proc/ClearSpaces 0.000 0.001 0.001 1000
/proc/ClearMiddleSpaces 0.000 0.000 0.000 19000
/proc/clearSpaces 0.000 0.000 0.000 1000


proc
clearSpaces(string)
var position = 1
while(findtext(string," ",position))
position = findtext(string," ",position)
if(text2ascii(string,position-1)==32)
string = copytext(string,1,position) + copytext(string,position+1)
else position++
return string