I am trying to split a string using 'split-string' function based on the . character. But
(split-string "1.2.3" ".")
doesn't work at all. It just returns a list of variable number of empty strings. Is . a special character that needs to be escaped or specified in some different way?
To split a string with specific character as delimiter in Java, call split() method on the string object, and pass the specific character as argument to the split() method. The method returns a String Array with the splits as elements in the array.
Splitting a string using strtok() in C In C, the strtok() function is used to split a string into a series of tokens based on a particular delimiter. A token is a substring extracted from the original string.
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
Here is the official documentation for split-string function - https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Strings.html
The second argument to the split-string function in (split-string "1.2.3" "\.")
is a regular expression and as a result both the '.' character and '' character have special meaning. So the '.' character needs to be escaped and even the '' character needs to be escaped with another ''. (split-string "1.2.3" "\\.")
will work fine as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With