您当前的位置: 首页 >  Java

梁云亮

暂无认证

  • 3浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Java13:文本块

梁云亮 发布时间:2021-10-09 17:13:21 ,浏览量:3

示例1
 public static void main(String[] args) {
        String text1= "春种一粒粟,秋收万颗子。\n" +
                "四海无闲田,农夫犹饿死。\n" +
                "锄禾日当午,汗滴禾下土。\n" +
                "谁知盘中餐,粒粒皆辛苦。";
        System.out.println(text1);
        System.out.println(text1.length());
        String text2 = """
                春种一粒粟,秋收万颗子。
                四海无闲田,农夫犹饿死。
                锄禾日当午,汗滴禾下土。
                谁知盘中餐,粒粒皆辛苦。
                """;
        System.out.println(text2);
        //长度之所以会多1,是因为最后的三个双引号和前面的字符串之间多了一个回车换行
        System.out.println(text2.length());
    }
示例2 符号作用\不换行\s空格
    public static void main(String[] args) {
        String text1= """
                select empno,ename,salary
                from tb_emp e
                inner join tb_dept d on e.deptno=d.deptno
                where dname='salary'
                order by empno desc 
                """;
        System.out.println(text1);
        String text2 = """
                select empno,ename,salary\s\
                from tb_emp e\s\
                inner join tb_dept d on e.deptno=d.deptno\s\
                where dname='salary'\s\
                order by empno desc 
                """;
        System.out.println(text2);
    }
示例3
public static void main(String[] args) {
    String str = """
            SELECT %s
            FROM %s
            ORDER BY id
            """;
    String res2 = String.format(str, "id,name,age,gender,birth", "tb_user")
            .trim().replaceAll(" \\s*", " ").replaceAll("(\r\n|\r|\n|\n\r)", " ");
    System.out.println(res2);
}
关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0435s