![]() not just in string and character literals see JLS sections 3.1, 3.2 and 3.3 for a details on the use of Unicode in Java source code. I am using following code to print logs that should include double quote in output. However, these are different from ordinary string and character escapes in that you can use them anywhere in a Java program. It is also worth noting that you can include arbitrary Unicode characters in your source code using Unicode escape sequences of the form \uxxxx where the xs are hexadecimal digits. \: It is used to insert a double-quote character in the text. \f: It is used to insert a form feed in the text. \’: It is used to insert a single quote of character in the text. \b: It is used to insert a backspace in the text. \t: It is used to insert a tab in the text. The complete list of Java string and character literal escapes may be found in the section 3.10.6 of the JLS. There are a total of 8 escape sequence in java. To print the sentence She said 'Hello' to me. For example, if you want to put quotes within quotes you must use the escape sequence, \', on the interior quotes. As you know, the double quote symbol has a special meaning in Java (displaying text). Horizontal tab and form feed: "\t" and "\f" The following table shows the Java escape sequences: When an escape sequence is encountered in a print statement, the compiler interprets it accordingly.Carriage return and newline: "\r" and "\n" Escaping the double quotes with backslashes is the only way to do this in Java.In addition, Option F is correct and shows one way to add three consecutive double quote marks inside a text block. ![]() Notice that the string that results in option E will be identical to that of option C. ![]() ('Good Morning\t Geeks ') Good Morning Geeks Java code for the escape sequence \b : // The escape sequence \b is a backspace character // It moves the cursor one character. Other characters that need special treatment include: Double quote \\ \ Backslash: The sequence \' inserts a double quote in a string. If you want three double quote marks in a row, you must escape at least one of them, or they will be taken as the end of the block. Java code for the escape sequence \t: // \t -> It gives a tab between two words. The double quote character has to be escaped with a backslash in a Java string literal.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |