Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Illegal character in string literal
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Luffy123




PostPosted: Thu May 10, 2012 8:15 pm   Post subject: 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 \.
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu May 10, 2012 8:22 pm   Post subject: 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




PostPosted: Fri May 11, 2012 1:12 pm   Post subject: RE:Illegal character in string literal

so to simplify, use \\ or /
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: