我正在尝试创建一个字符串,将所有空格替换为*,但我无法确定如何做到这一点。有人能帮忙吗?
String phrase = new String ("This is a String test.");
Mystring = Mystring.Replace(' ', '*');
String phrase = new String ("This is a String test.");
/*Replace the Spaces with the *, */
String finalString = phrase.Replace(' ', '*');
System.out.println(finalString);
String phrase = "This is a String test.";
足够了。使用new运算符创建字符串会创建两次字符串。
var result = phrase.Replace(' ', '*');
。 - Alex Aza