Skip to content

String

Write a string

Given a file named “main.scm” with:

(import (scheme base))
(write-string "Hello, world!")

When I successfully run scheme main.scm

Then the stdout should contain exactly “Hello, world!”.

Convert a string to a list

Given a file named “main.scm” with:

(import (scheme base))
(for-each write-char (string->list "Hello, world!"))

When I successfully run scheme main.scm

Then the stdout should contain exactly “Hello, world!”.

Convert a list to a string

Given a file named “main.scm” with:

(import (scheme base))
(write-string (list->string (string->list "Hello, world!")))

When I successfully run scheme main.scm

Then the stdout should contain exactly “Hello, world!”.

Append strings

Given a file named “main.scm” with:

(import (scheme base))
(write-string (string-append <values>))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

valuesoutput
""
"foo”foo
”app” “le”apple
”dis” “cov” “ery”discovery

Get a character in a string

Given a file named “main.scm” with:

(import (scheme base))
(write-char (string-ref "<string>" <index>))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

stringindexoutput
a0a
ab0a
ab1b
abc0a
abc1b
abc2c

Get a length of a string

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (string-length "<value>") <length>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

valuelength
0
a1
aa2
aaa3

Get a sub-string

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (equal? (substring "<value>" <start> <end>) "<output>") 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

valuestartendoutput
00
a00
a01a
ab00
ab01a
ab12b
ab02ab
abc00
abc01a
abc12b
abc23c
abc02ab
abc13bc
abc03abc

Check string equality

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string=? "<value>" "<value>") 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

value
a
ab
abc

Check string inequality

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string=? "<left>" "<right>") 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “B”.

Examples

leftright
a
a
ab
aab
aba
aaab
aaaaa
aaaaa
aaaaab
aabaaa

Check a string order

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string<? "<left>" "<right>") 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

leftright
a
ab
aaa
aaab
aaaaa
aaaaab

Check a string order inverse

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (not (string<? "<left>" "<right>")) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

leftright
a
aa
ba
aaa
aaaa
abaa
baaa
baab