Reputation: 21
For example
I have a file testing.txt
that reads
read 3 4
Consider
(define file(open-input file "testing.txt"))
I want to remove the r
in read
instead of the whole word, I want to update file without the first character r
, I know I can not use this using cdr file
because it erases the word read
.
Any suggestions?
Upvotes: 2
Views: 526
Reputation: 236132
A couple of hints for your homework. This will return a list, with each line of the file as a string in the list:
(define lines (file->lines "testing.txt"))
This procedure will write an input text
to a file in the given path
, overwriting the contents of the file:
(define (write-to-a-file path txt)
(call-with-output-file path
(lambda (output-port)
(display txt output-port))
#:exists 'replace))
You can use the procedures string->list
, list->string
(see the documentation), car
and cdr
to manipulate the list returned by file->lines
, and write the resulting text using write-to-a-file
. Now you have all you need to solve the problem by yourself.
Upvotes: 1