Re: String to Integer



adam wrote:
Lew wrote:

Integer i = '\n';

is what you want.


Thanks for answering so quickly!

The thing is that I have a String var with characters such as "0", "a", "\n"... I use String.charAt(0) for getting the first character of the string. It works nice when I'm using a normal character ('0', 'a'...) but it doesnt with escape characters (it gets '\' instead of '\n').

So the question is: how can convert a string "\n" into an integer?
Or how can I convert "\n" into a char for then converting it to an integer??

\n is an escape sequence for string and character literals. If read from a file or the keyboard, the IO system does not assume that you really meant a \ to mean something else, it just reads what is there. If you want a newline in a file or at the keyboard, hit Enter.

I don't know of Java class that will parse string literal escapes for you. Considering there's only a few of them, doing it yourself should not be hard.
.



Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • Re: problems with opening files due to files path
    ... GUI or it is a console app. ... of what an escape character and escape sequence is. ... character) inside a string specially, it makes the character after the ...
    (comp.lang.python)
  • Re: html_entity_decode + regex = profit?
    ... I've got an incoming string with a caret that's been escaped to ... The caret isn't a legal character where it's going (a text ... You can also use preg_quoteto escape metacharacters in a string. ...
    (comp.lang.php)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)