使用replaceall输出错误 [英] Wrong output using replaceall

查看:118
本文介绍了使用replaceall输出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我从以下代码获得AAAAAAAAA而不是1A234A567:

Why do i get "AAAAAAAAA" instead of "1A234A567" from following Code:

String myst = "1.234.567";

String test = myst.replaceAll(".", "A");

System.out.println(test);

任何想法?

推荐答案

replaceAll 函数将正则表达式作为参数。而正则表达式。意思是任何角色。您必须转义它以指定它是您想要的字符: replaceAll(\\。,A)

replaceAll function take a regular expression as parameter. And the regular expression "." means "any character". You have to escape it to specify that it is the character you want : replaceAll("\\.", "A")

这篇关于使用replaceall输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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