Java中的字符串问题 [英] string problem in java

查看:64
本文介绍了Java中的字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想在字符串中保存一些文件路径时,例如:(c:\ abc \ das \ sdd \ sdf.txt),因此它会自动删除所有''\'',任何人对此都有解决方案....

when i want to save some file path in string like:(c:\abc\das\sdd\sdf.txt) so it remove all ''\'' automatically any one have solution for this....

推荐答案

使用双引号代替单斜杠,如下所示:

Use double in stead of single slashes, like so:

c:\\abc\\das\\sdd\\sdf.txt



否则,编译器会将斜线后的字符解释为转义字符.



Otherwise the compiler interprets the character after a slash as an escape character.


必须将''\''字符转义(即重复,因为它是 )放在字符串中,请使用:
the ''\'' charachter must be escaped (i.e. repeated, since it is the escape character) in strings, use:
C:\\abc\\das\\sdd\\sdf.txt


:)


这篇关于Java中的字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆