Escape sequence hell with traditional string literals

To add a newline or tab to a traditional string value, you can use the escape sequences and . Escape sequences are letters preceded with (a backslash), and they have a special meaning in Java. For example in Java strings,  is used as a newline, and is used as a tab.

An escape sequence is a letter combination used for values that can't be represented directly. For instance, to use the newline control character from ASCII, Java uses . Java defines multiple other escape sequences.

The following code shows how you can store the multiline string value with newline and tab escape sequences. The newline and tab escape sequences will include the indentation in the variable HTML:

String html = "<HTML>
	<BODY>
		<H1>Meaning in life</H1>
	</BODY>
</HTML>"; 

As you can see, the preceding can be difficult to write. You'll have to figure out the newlines and count the tabs in the target string value, and insert them as or . Another challenge is reading this code. You'll have to try to figure out line by line what the code is intended to do.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179