(defun splitStr (str)
"Appends characters from str to my-string unless the character is a space. When a space is encountered, add the current my-string to a new list."
(setq my-string "") ;; Initialize my-string as an empty global string
(setq result-list '()) ;; Initialize an empty list to store parts of the string
(setq len (length str)) ;; Get the length of the input string
(dotimes (i len)
(setq curr-char (char str i)) ;; Get the character at index `i`
(if (char/= #\Space curr-char) ;; If the character is not a space
(setq my-string (concatenate 'string my-string (string curr-char))) ;; Append character to my-string
(when (> (length my-string) 0) ;; If my-string is not empty
(push my-string result-list) ;; Add my-string to result-list
(setq my-string "")))) ;; Reset my-string to empty string
;; After the loop, add the final my-string if it's not empty
(when (> (length my-string) 0)
(push my-string result-list))
(nreverse result-list)) ;; Return the reversed list to maintain original order
;; Example usage
(princ (splitStr "I feel joy")) ;; Output: ("I" "feel" "joy")
KGRlZnVuIHNwbGl0U3RyIChzdHIpCiAgIkFwcGVuZHMgY2hhcmFjdGVycyBmcm9tIHN0ciB0byBteS1zdHJpbmcgdW5sZXNzIHRoZSBjaGFyYWN0ZXIgaXMgYSBzcGFjZS4gV2hlbiBhIHNwYWNlIGlzIGVuY291bnRlcmVkLCBhZGQgdGhlIGN1cnJlbnQgbXktc3RyaW5nIHRvIGEgbmV3IGxpc3QuIgogIChzZXRxIG15LXN0cmluZyAiIikgIDs7IEluaXRpYWxpemUgbXktc3RyaW5nIGFzIGFuIGVtcHR5IGdsb2JhbCBzdHJpbmcKICAoc2V0cSByZXN1bHQtbGlzdCAnKCkpICA7OyBJbml0aWFsaXplIGFuIGVtcHR5IGxpc3QgdG8gc3RvcmUgcGFydHMgb2YgdGhlIHN0cmluZwogIChzZXRxIGxlbiAobGVuZ3RoIHN0cikpICA7OyBHZXQgdGhlIGxlbmd0aCBvZiB0aGUgaW5wdXQgc3RyaW5nCiAgCiAgKGRvdGltZXMgKGkgbGVuKQogICAgKHNldHEgY3Vyci1jaGFyIChjaGFyIHN0ciBpKSkgIDs7IEdldCB0aGUgY2hhcmFjdGVyIGF0IGluZGV4IGBpYAogICAgKGl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