One of my favorite string scripts from Python. I can't live without it.

StringStrip will strip the leading or trailing characters from a particular string. This is very, very useful for parsing. Just to show an example, you have a command:"-gold 500"Normally, you would read it as SubString(text, 6, StringLength(text)), and convert it to an integer. But what if someone types it like this?" -gold 600 "That should be perfectly acceptable, but the system will interpret it as "d 600 ". If you try to convert that, it will return 0. There are many ways to approach that problem, but one way is using StringStrip(). Simply:

Code: jass

call StringStrip(" -gold 600 ", " ")

The returned string will be, "-gold 600", ready for reading.

To understand it better, it is kind of like StringReplace() or remove, but with only leading and trailing characters.

It is mostly useful for spaces, but you can use other characters too--even multiple ones:"xxxtestxxx" -> StringStripLeft("xxx") -> "testxxx""testing" -> StringStripRight("ing") -> "test"As far as complexity goes, this is a very lightweight function, despite how large it looks. It can be implemented recursively, but recursiveness is generally a bad idea in wc3 speed-wise. It doesn't generate any more strings than it needs, as well.

Hmm, took me a little bit to understand it.I personally think the names should be swapped. Not sure if I'm right in that.Unfortunately I did not understand how the third function should be called, if at all.Edit: nevermind, I got it.So, basically StringStrip the third function as I understand it should be called StringStripMiddle, the others should be swapped from StringStripRight to StringStripLeft and from StringStripLeft to StringStripRight. Or just leave it all the same and replace the word Middle with Both or the word Sides. Anyway, not sure if a Library name should be the same as a Function name. I guess it compiles or you wouldn't have posted the code, but it could be confusing for the layman.

What's this site?

Here is the place where making your favorite games can be possible, with the support of a cordial and warm community. Here you will find resources that will help you develop your projects in an effective and agile way. In addition, you can show your projects, share your ideas or simply contribute with resources to establish bonds with a growing community, forming in the process the network of fanatic users to do Modding and mapping Warcraft 3.