Welcome to Phrogram Sign in | Join | Help


Re: Unable to create a single backslash ("\\")

  •  12-06-2006, 11:28 PM

    Re: Unable to create a single backslash ("\\")

    Tony,

    You may already figured out (but I don't think that it's in the documentation) that backslash is a special character in strings. There are, I believe, fivespecial sequences that are recognised by Phrogram (and many other programming languages like C, C++, Java, C# ...). These are:

    • \n - represents a 'newline' character
    • \r - represents a 'carriage return' character
    • \t - represetns a 'tab' character
    • \" - represents a double-quote character (doesn't terminate the string)
    • \\ - represents a (single) backslash character

     It's actually only the IDE itself that seems to have a problem, not the compiler. That problem is with handling a double backslash before the end of the string. So the following program:
     

    Program Test

          Method Main()
                PrintLine(
    "\\")
                PrintLine("
    \\ Hello")
                PrintLine("
    \"")
         
    End Method

     End Program

    looks wrong, but does actually run and outputs:

    \
    \ Hello
    "

    as it should. Now, until the IDE is fixed, there is a workaround you can use to fool it into highlighting the syntax correctly, like this:

     

    Program Test     

          Method Main()
                PrintLine(
    "\\")
                // Fool IDE into closing string and method -- "
    )
                PrintLine(
    "\\ Hello")
                PrintLine(
    "\"")
         
    End Method

    End Program

    If you put the "special" comment containing ") after the offending line you can persuade the IDE to get the rest of the formatting correct.

    One final thing. If the reason that you have the sequence \\ at the end of a string is that you're trying to deal with file pathnames, a very easy workaround is to use '/' instead of '\' as the path delimiter. Windows accepts either.

    Neil

    Filed under: ,
View Complete Thread