gpt4 book ai didi

string - 小写 Racket 中的整个字符串

转载 作者:行者123 更新时间:2023-12-04 17:36:55 29 4
gpt4 key购买 nike

有没有办法在 Racket 中将字符串中的所有字符都变成小写?

我能想到的唯一方法是将字符转为小写,但它不适用于字符串

我使用的是初学者语言,所以我无法使用某些功能

最佳答案

在实践中,你会使用 string-downcase 程序:

(string-downcase "ABCDE")
=> "abcde"

但是您正在使用初学者的语言工作,所以这里是解决它的一般想法 - 我会给您一些提示,如果您尝试自己解决问题会更好。首先,让我们将问题分为两部分:一个过程将字符串转换为字符列表,调用执行实际转换的辅助过程,最后将转换后的列表转换回字符串:
(define (lowercase str)
(<???> ; convert the list of chars into a string
(convert ; call the helper procedure
(<???> str)))) ; convert the string into a list of chars
convert procedure 是一个助手,它完成繁重的工作并将字符列表中的每个字符转换为小写:
(define (convert strlst)
(if <???> ; if the list of chars is empty
<???> ; return the empty list
(cons ; else `cons`
(<???> <???>) ; convert to lowercase the first char in list
(convert <???>)))) ; advance recursion over list

解决方案的关键部分是操作程序 stringscharacters ,单击链接并研究文档。

关于string - 小写 Racket 中的整个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15779906/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com