Question

I have this code which finds double quotation marks and converts the inside of those quotation marks into a string. It manages to find the first quotation mark but fails to find the second so: "this" would be "this . How do I get it I can get this function to find the full string.

Was it helpful?

Solution

Maybe this is too obvious:

if (ch = #"\"") then SOME(String(x ^ "\""))

OTHER TIPS

I do not really understand your code: you return the string just after the first occurence of the quotation mark, but this string has been built with the characters that you've found before it. Moreover, why do you return SOME(Error) instead of NONE?

You need to use a boolean variable to know when the first quotation mark has been seen and to stop when the second one is found. So I would write something like this:

fun parseString x inStr quote =
  case (TextIO.input1 inStr, quote) of
     (NONE, _) => NONE
   | (SOME #"\"", true)  => SOME x
   | (SOME #"\"", false) => parseString x inStr true
   | (SOME ch, true)     => parseString (x ^ (String.str ch)) inStr quote
   | (SOME _ , false)    => parseString x inStr quote;

and initialize quote with false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top