Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string into individual characters

I am having two problems while working in Lisp and I can't find any tutorials or sites that explain this. How do you split up a string into its individual characters? And how would I be able to change those characters into their corresponding ASCII values? If anyone knows any sites or tutorial videos explaining these, they would be greatly appreciated.

like image 427
Nick Welki Avatar asked Apr 18 '11 17:04

Nick Welki


People also ask

How do I split a string into a list of words?

To turn that string into a list of words, use the split() method. You don't need to specify a separator or a maxsplit paramter, as we want to separate all the words wherever there is whitespace between them.


2 Answers

CL-USER 87 > (coerce "abc" 'list)
(#\a #\b #\c)


CL-USER 88 > (map 'list #'char-code "abc")
(97 98 99)

Get the Common Lisp Quick Reference.

like image 182
Rainer Joswig Avatar answered Sep 21 '22 07:09

Rainer Joswig


A Lisp string is already split into its characters, in a way. It is a vector of characters, and depending upon what you need to do, you can use either whole string operations on it, or any operations applicable to vectors (like all the operations of the sequence protocol) to handle the individual characters.

like image 30
Rörd Avatar answered Sep 18 '22 07:09

Rörd