In my code i am trying to check if a string have a specific prefix, to do so,I am using the equal? and string-ref function. but it doesn't seem to work as expected
here is the part I'm talking about:
(: plPrefixContained : String -> Boolean)
(define (plPrefixContained x )
(equal? (string-ref x 0) "p"))
(test (plPrefixContained "pcenuc") => true)
I was checking this specific function, that should return true, but I keep getting false for the test. I was trying to change "p" to #/p" and I was trying to use string=? and eq? insted of equal? but nothing.
Any help would be appreciated
(test (plPrefixContained "pcenuc") => true)
I'm using DRracket and the language is #lang pl
Remember that string-ref returns a character, not a string. For the comparison to succeed, use #\p instead of "p".
(define (plPrefixContained x )
(equal? (string-ref x 0) #\p))
The above will work. But to make it more explicit, you should use char=? instead of equal?, in this way you'll remember that the comparison is between characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With