Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 13-Sep-14 23:45pm
v2

1 solution

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 index length − 1. Also see the procedure "string-length string".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900