几个特殊字符在String中的转义表达式

本文通过一个Java示例程序详细展示了各种转义字符的效果,包括单引号、双引号、反斜线、制表符、回退符、回车符、走纸符和换行符等,并对每种转义字符的显示效果进行了说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、未解决的问题:有点奇怪的是:回退字符,并没有出现大家说的问题,就是出现回退字符的后面字符会吃掉前面的一个字符。不知道是为什么。


2、测试code:

public class Main{
    public static void main(String[] args) {
        // Scanner in = new Scanner(System.in);
        //单引号
        String str1="I\'love\'working!";
        //双引号
        String str2="I\"love\"working!";
        //反斜线
        String str3="I\\love\\working!";
        //制表符
        String str4="I\tlove\tworking!";
        //回退符
        String str5="I \blove \bworking!";
        //回车符:将当前位置移到本行开始:故会覆盖\r之前输出的字符
        String str6="I\rlove\rworking!";
        //走纸符
        String str7="I\flove\fworking!";
        //换行符:将当前位置移到下一行开始
        String str8="I\nlove\nworking!";

        //输出:
        System.out.println("单引号--------------");
        System.out.println(str1);
        System.out.println();

        System.out.println("双引号--------------");
        System.out.println(str2);
        System.out.println();

        System.out.println("反斜线--------------");
        System.out.println(str3);
        System.out.println();

        System.out.println("制表符--------------");
        System.out.println(str4);
        System.out.println();

        System.out.println("回退符--------------");
        System.out.println(str5);
        System.out.println();

        System.out.println("回车符--------------");
        System.out.println(str6);
        System.out.println();

        System.out.println("走纸符--------------");
        System.out.println(str7);
        System.out.println();

        System.out.println("换行符--------------");
        System.out.println(str8);
        System.out.println();

    }
}


输出结果:

单引号--------------
I'love'working!

双引号--------------
I"love"working!

反斜线--------------
I\love\working!

制表符--------------
I	love	working!

回退符--------------
Iloveworking!

回车符--------------
working!

走纸符--------------
I love working!

换行符--------------
I
love
working!





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值