Javascript - Replacing the escape character in a string literal

前端 未结 4 616
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 05:38

I am trying to replace the backslash (escape) character in a Javascript string literal.

I need to replace it with a double backslash so that I can then do a redirec

4条回答
  •  温柔的废话
    2020-12-03 06:22

    << Escape Characters Replacement>>

    import java.util.Scanner;
    
    public class Example7 {
    
      public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        System.out.println("Please enter a sentence: ");
        String a=in.nextLine();
        //System.out.println("the word had enter: "+a);
    
        String Str1 = a.replace("\\n", "(new_line)");
        //System.out.println(Str1);
        String Str2 = Str1.replace("\\t", "(tab)");
        //System.out.println(Str2);
        String Str3 = Str2.replace("\\t", "(tab)");
        String Str4 = Str3.replace("\\\\", "(comment_line)");
        String Str5 = Str4.replace(":)", "(smile) ");
        System.out.println("The new sentence:"  +Str5);
      }
    }
    

提交回复
热议问题