Page 1 of 1

New useful helper functions to manipulate strings

Posted: Mon Jul 28, 2008 9:47 pm
by digdug
On IRC me and Betel prepared a function that converts an arbitrary string to a list (well I wrote the code and Betel rewrote it to make it working :lol: )

(intConvertStringToList string)
will convert a string to a list of characters
Example:
"Hello World!" ---> (h e l l o " " w o r l d !)
(the " " is the space character that is properly parsed)


This function made also trivial the implementation of subString and CharAt and Tokenize.

(substring string index1 index2)
will return a trimmed string depending on the indexes
Example:
(substring "abcde" 3 4)
Returns: "de"

(charAt string index)
will return the character at the submitted index
Example:
(charAt "hello" 1)
Returns: "e"

(tokenize string delimiter)
will return a list containing the string tokens cutted by the delimiter (only one, i'm not a programmer)
Example:
(tokenize "hello world i'm here" " ")
Returns:
'("hello" "world" "i'm" "here")


so here the mod with the 4 functions:
http://xelerus.de/index.php?s=mod&id=150



Functions like these can be powerful tools.
How many applications can you think about ?

Posted: Mon Jul 28, 2008 10:56 pm
by Betelgeuse
very cool I know I have been wanting something like a tokenize function.

Posted: Tue Jul 29, 2008 9:11 pm
by digdug
application that can be done with these functions that I can think about:

generation of random items by changing a number in a unid name.
like changing weapon1 to weapon2.

aliens that mispell name of objects or the name of systems.

anagrams (in 0.99)

Posted: Tue Jul 29, 2008 10:49 pm
by Betelgeuse
why don't you take that idea a step farther and make items stat reflected in their names.

Such as

unid.Weapon.Ion.5d6.FR10

so you could generate items based on what stats you wanted :D

Posted: Tue Jul 29, 2008 11:01 pm
by Betelgeuse
sorry now that I think of it that being a modifier would be better (ether as a whole or in parts)

but even so whenever you want to manipulate strings these are great