Search code examples
stringtext-processingnewlisp

loop over characters in string, NewLISP


I need to loop over the characters in a given string--in Ruby, I'd do something like this:

string = "blah"

string.each_char do |c| 

   puts c

end

How do I do this in newLisp?


Solution

  • Note that dostring supplies integers:

    (let (str "šŸ˜„šŸ˜ƒšŸ˜€šŸ˜Š")
    (dostring (c str)
      (println (format "%x" c))))
    
    1f604
    1f603
    1f600
    1f60a
    

    whereas explode supplies the characters:

    (let (str "šŸ˜„šŸ˜ƒšŸ˜€šŸ˜Š")
    (dolist (c (explode str))
      (println c)))
    
    šŸ˜„
    šŸ˜ƒ
    šŸ˜€
    šŸ˜Š