[racket-users] Re: Compare parts of string or compare with wildcard.
Hi Ken, string-prefix? does exactly what you want. > (define a "this") (define b "that") (define c "thisandthat") > (string-prefix? c a) #t > (string-prefix? c b) #f https://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-prefix~3f%29%29 Best, Shu-Hung On Friday, October 28, 2016 at 11:19:26 AM UTC-5, Ken MacKenzie wrote: > I have two things I am trying to compare, both strings. > > What I want to know is if string a is the beginning of string b. > > Example (pseudo code) > > string a = this > string b = that > string c = thisandthat > > a... == c #t > b... == c #f > > Hope I am making sense here. I couldn't figure out a way so at present my > program does this > > (define alen (length astr)) > (define bpart (substring bstr 0 alen)) > (cond > [(string=? astr bpart) #t] > [else #f]) > > That is working, but it seems like there should be a simpler solution to this. > > Ken -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] Re: Compare parts of string or compare with wildcard.
Excellent thank you. To note I am searching the docs but I see I did not scroll far enough. I went to go find string-prefix in the doc and also found string-contains and string-suffix in the same set of examples. So you gave me an inadvertent trifecta of useful information. It also means that where the original code was used as part of a filter (lambda(x) expression I should be able to ditch the extra function and just handle as a filter (string-prefix. Ken On Friday, October 28, 2016 at 12:34:29 PM UTC-4, Shu-Hung You wrote: > Hi Ken, > string-prefix? does exactly what you want. > > > (define a "this") (define b "that") (define c "thisandthat") > > (string-prefix? c a) > #t > > (string-prefix? c b) > #f > > https://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-prefix~3f%29%29 > > Best, > Shu-Hung > > > Ken -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.