scheme - 方案 - 字符串附加两个字符串列表
问题描述
我正在尝试附加两个字符串列表
但我不知道如何在两个单词之间添加空格。
(define (string-concat lst1 lst2)
(map string-append lst1 lst2)
)
(string-concat '("elementary") "(school))
然后结果为“小学”
它们合并时如何添加空间?我尝试使用 lambda 但它不起作用,例如
(map string-append (cdr (append* (map (lambda (x) list " " x)) lst1)) lst2)
解决方案
您可以简单地在两个字符串之间添加一个空格,string-append
接受多个参数:
(string-append "hello" " " "world")
=> "hello world"
或者你可以使用string-join
:
(string-join '("hello" "world"))
=> "hello world"
现在,将其扩展到字符串列表:
(map (lambda (s1 s2) (string-append s1 " " s2))
'("a" "b" "c")
'("1" "2" "3"))
=> '("a 1" "b 2" "c 3")
(map (lambda (s1 s2) (string-join (list s1 s2)))
'("a" "b" "c")
'("1" "2" "3"))
=> '("a 1" "b 2" "c 3")
推荐阅读
- scala - 从 Schema Scala 中提取列详细信息和类型
- javascript - 如果该字符与第一个输出的字符相同,如何防止显示第二个按键的输出?
- r - plm 中只有两个 ID 的重复情侣(id-time)错误
- c++ - shmget() 在 Netbeans 中运行失败
- r - 根据较短的df条件填充较长的变量
- python - Geopandas python空几何/缺失值
- python - 如果单击另一个反应,我如何自动删除反应?不和谐重写
- robotframework - 机器人框架 FOR 循环给出错误作为变量 ${i} 未找到
- python - cls 用于不是类的python函数
- swift - 遇到错误时如何将 URL 转换为 NSString:只能存储 NSNumber、NSString、NSDictionary 类型的对象?