Including escape sequences as part of string values

Imagine what happens when the letter combination represented by an escape sequence (let's say,  ) must be included as a part of the string value. Let's modify our example, as follows:

<HTML> 
   <BODY> 
          <H1>
 - new line, 	 - tab</H1>  
   </BODY> 
</HTML> 

In this case, you can escape the sequence by using another backslash, as follows:

String html =  "<HTML>" + 
                    "
	" + "<BODY>" + 
                        "
		" + "<H1>\n - new line, \t - tab</H1>" 
+ " " + "</BODY>" + " " + "</HTML>";

But, with the changes, it's getting difficult to read and understand the preceding code. Imagine a developer in your team writes such code. Let's see how you could make it more readable. 

As a workaround, you can define String constants (say, tab or newLine), assigning the values of  and  to them. You can use these constants instead of the literal values of  and in the preceding code. This replacement will make the code easier to read. 

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

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