Clear Spaces

by Lugia319
Pesky spaces in chat? I can fix that! [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Lugia319.ClearSpaces##version=2

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Lugia319.ClearSpaces##version=2

50 downloads
Version 1.1
Date added: Dec 17 2013
Last updated: Dec 20 2013
1 fan
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]"

Comments

Kozuma3: (Mar 27 2015, 9:29 am)
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
Lugia319: (Dec 19 2013, 7:48 am)
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.
Kaiochao: (Dec 18 2013, 6:21 pm)
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
Toddab503: (Dec 18 2013, 6:11 pm)
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?
Kaiochao: (Dec 18 2013, 4:51 pm)
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.