java - How to handle special characters like "\n" in string reverse? -


I have the following code to reverse a string, and I am considering doing test cases for it . I would like to know how the user input "\ n", "\ t"?

  Private static string reverse 2 (string straight) {if (str == null || Str.length () == 0) return str; Int start = 0; Int end = str.length () - 1; Four [] characters = str.toCharArray (); While (start & lt; end) {four tmp = characters [begin]; Character [start] = character [end]; Character [end] = tmp; Start ++; End--; } Return String.valueOf (character); }    

"\ nxyz" like string, str.toCharArray (); TRAVET "\ n" There is no problem with your code as a single character, only one thing in the new line will change and this will print in different lines this time.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -