栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

检查字符串是否包含 n Java

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

检查字符串是否包含 n Java

如果字符串是在同一程序中构造的,则建议使用以下命令:

String newline = System.getProperty("line.separator");boolean hasnewline = word.contains(newline);

但是,如果您指定使用 n,则此驱动程序说明了如何做:

class newlineTest {    public static void main(String[] args) {        String hasnewline = "this has a newlinen.";        String nonewline = "this doesn't";        System.out.println(hasnewline.contains("n"));        System.out.println(hasnewline.contains("\n"));        System.out.println(nonewline.contains("n"));        System.out.println(nonewline.contains("\n"));    }}

导致

truefalsefalsefalse

回应您的评论:

class newlineTest {    public static void main(String[] args) {        String word = "testn.";        System.out.println(word.length());        System.out.println(word);        word = word.replace("n","n ");        System.out.println(word.length());        System.out.println(word);    }}

结果是

6test.7test .


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497018.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号