zoukankan      html  css  js  c++  java
  • java和javascript双引号嵌套的问题

    双引号不能嵌套双引号,否则一对双引号就结束了。

    java中双引号中嵌套双引号需要转义:

        /**
         * java双引号转义符测试
         * @author asus
         *
         */
        public static void main(String[] args) {
            
            String ont = ""name"";        //字符串两边含有双引号    
            String tow = "name "is" wgb"; //字符串中间含有双引号    
            String three = "\name";        //使用转义字符还可以使字符串包含其他字符    
                
            System.out.println("字符串ont  :" + ont);   
            System.out.println("字符串tow  :" + tow);   
            System.out.println("字符串three:" + three);
        }

    控制台结果:

    JavaScript中表示字符串时,可以用双引号,也可以用单引号。

    当拼接JS字符串的时候,双引号里面一定要是单引号,单引号里面要是双引号。如此循环!不过全部双引号也可以,就是双引号里面的双引号需要转义!

           /**
            * 当拼接JS字符串的时候,双引号里面一定要是单引号,单引号里面要是双引号(需转义)。如此循环!不过全部双引号也可以,就是双引号里面的双引号需要转义!
            */
           var inShort="What do the 'guards "at" Buckingham Palace' wear on their heads?";
           
           var inShort="What do the "guards "at" Buckingham Palace" wear on their heads?";
  • 相关阅读:
    Codeforces Round #251 (Div. 2) A
    topcoder SRM 623 DIV2 CatAndRat
    topcoder SRM 623 DIV2 CatchTheBeatEasy
    topcoder SRM 622 DIV2 FibonacciDiv2
    topcoder SRM 622 DIV2 BoxesDiv2
    Leetcode Linked List Cycle II
    leetcode Linked List Cycle
    Leetcode Search Insert Position
    关于vim插件
    Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's Stones
  • 原文地址:https://www.cnblogs.com/wkrbky/p/5961225.html
Copyright © 2011-2022 走看看