String Functions in Racket
This Racket code demonstrates various string operations similar to those in the original Go example. Here’s a brief explanation of the changes:
- We use
#lang racket
to specify the Racket language. - We import the
racket/string
module which provides many string functions. - Instead of
fmt.Println
, we define a shorthand p
for displayln
. - Racket’s string functions are slightly different from Go’s:
string-contains?
replaces Contains
string-count
replaces Count
string-prefix?
and string-suffix?
replace HasPrefix
and HasSuffix
string-index-of
replaces Index
string-join
replaces Join
make-string
replaces Repeat
string-replace
replaces Replace
string-split
replaces Split
string-downcase
and string-upcase
replace ToLower
and ToUpper
- We use
string-append
to concatenate strings for output. - Some functions return booleans, so we use
number->string
to convert them to strings for display.
When you run this Racket program, it will produce output similar to the Go version, demonstrating various string operations in Racket.