
-----------------------------------
Luffy123
Thu May 10, 2012 8:15 pm

Illegal character in string literal
-----------------------------------
I was importing a class so the location was

C:\Users\Downloads...

so i put this as the import

Import Name in "C:\Users\Downloads..."

without the  ... of course but it said illegal character in string literal turned out I had to change /  to this one \ and then it worked. Why is that? My address bar had \.

-----------------------------------
DemonWasp
Thu May 10, 2012 8:22 pm

RE:Illegal character in string literal
-----------------------------------
The backslash (\) is an "escape character".

Suppose you want to put a double quote in your strings -- well, you'd be screwed because double-quote ends a string. However, if you write \", then you will escape the double quote, so it won't have its usual effect.

That creates another problem, though: what if you want to write an actual backslash? Simple -- escape it too. Write \\ and you'll get \, inside a string context.

The reason that forward slash works is that somewhere (probably in a Windows API call) paths containing / are converted to the (correct-for-Windows) path separator of \ .

Other escape characters include \t (tab) and \n (newline). \(space) is not valid -- hence, "Illegal character in string literal".

-----------------------------------
Raknarg
Fri May 11, 2012 1:12 pm

RE:Illegal character in string literal
-----------------------------------
so to simplify, use \\ or /
