I want to convert ("USERID=XYZ" "USERPWD=123")
to "USERID=XYZ&USERPWD=123"
. I tried
(apply #'concatenate 'string '("USERID=XYZ" "USERPWD=123"))
which will return ""USERID=XYZUSERPWD=123"
.
But i do not know how to insert '&'? The following function works but seems a bit complicated.
(defun join (list &optional (delim "&")) (with-output-to-string (s) (when list (format s "~A" (first list)) (dolist (element (rest list)) (format s "~A~A" delim element)))))
To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.
You can concatenate a list of strings into a single string with the string method, join() . Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string.
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.
Use FORMAT.
~{
and ~}
denote iteration, ~A
denotes aesthetic printing, and ~^
(aka Tilde Circumflex in the docs) denotes printing the , only when something follows it.
* (format nil "~{~A~^, ~}" '( 1 2 3 4 )) "1, 2, 3, 4" *
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