New useful helper functions to manipulate strings

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

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 ?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

very cool I know I have been wanting something like a tokenize function.
Crying is not a proper retort!
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

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)
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

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
Crying is not a proper retort!
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

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
Crying is not a proper retort!
Post Reply