New useful helper functions to manipulate strings
Posted: Mon Jul 28, 2008 9:47 pm
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 )
(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 ?
(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 ?