如何从非空字符串(DrRacket)中提取最后一个字符。希望得到帮助 [英] How do you extract the last character from a non-empty string (DrRacket). Hope for assistance
问题描述
我对Scheme很新,我正在使用DrRacket,我希望得到一些急需的帮助。
我的第一个任务是提取第一个来自非空字符串的字符,我成功地这样做了。
;;签名:字符串优先:字符串 - > string
;;目的:从非空字符串中提取第一个字符
;;测试
(check-expect(string-第一个cookies)c)
(check-expect(字符串优先聚会)p)
;;定义:string-first
(define(string-first str)
(string-ith str 0))
现在,我是负责从非空字符串中提取最后一个字符。我无法弄清楚这一点。我的猜测是它涉及字符串长度与string-ith相结合。
希望有人可以帮助我。提前谢谢。
阅读文档有什么问题?请参阅:
http:/ /sicp.ai.mit.edu/Fall-2004/manuals/scheme-7.5.5/doc/scheme_7.html [ ^ ]。
找到过程:过程:string-ref string k
。指数从零开始,因此您需要索引length - 1
。另请参阅过程string-length string
。
-SA
I'm fairly new to Scheme and I'm using DrRacket and I hope to get some much needed assistance.
I was first tasked to extract the first character from a non-empty string, which I was successful in doing so.
;;Signature: string-first: string -> string
;;Purpose: To extract the first character from a non-empty string
;;Tests
(check-expect (string-first "cookies") "c")
(check-expect (string-first "party") "p")
;;Definition: string-first
(define (string-first str)
(string-ith str 0))
Now, I am tasked with extracting the last character from a non-empty string. I cannot figure this out. My guess is that it involves "string-length" in combination with "string-ith."
Hopefully someone can help me out. Thank you in advance.
What's wrong with just reading the documentation? Please see:
http://sicp.ai.mit.edu/Fall-2004/manuals/scheme-7.5.5/doc/scheme_7.html[^].
Locate the procedure: "procedure: string-ref string k
". Indices are zero-based, so you need the indexlength − 1
. Also see the procedure "string-length string
".
—SA
这篇关于如何从非空字符串(DrRacket)中提取最后一个字符。希望得到帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!