Search code examples
smlsmlnj

SML Check if String starts with letter


I'm very new to SMLNJ and was wondering how you go about something simple as checking if a string starts with a letter or starts with a " and then returning true or false.

Example: If a string looks like

"aaaaa" then return true
"\"aaaa\"" then return true
"25aaaa" then return false

Solution

  • You can cobble together a solution using some Standard Basis Library functions:

    fun checkFirst s =
       let val c = String.sub(s,0) in
            c = #"\"" orelse Char.isAlpha(c) 
       end;