正如标题所说,我想从字符串中删除一个特定字符(在这种情况下它是' e')但如果该字母是在,我不想删除它字符串的开头或结尾。
import java.util.Scanner;
public class RemoveE {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s;
String st;
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
s = in.nextLine();
st = s.replaceAll("e", "");
System.out.println(st);
}
}
答案 0 :(得分:0)
一个非常简单的解决方案是使用2个布尔变量,它告诉你在开头或结尾是否有那个字符,然后将它们全部删除,如果布尔值为真,则只需将它们添加回来。
boolean front = s.startsWith("e");
boolean end = s.endsWith("e");
s = s.replaceAll("e", "");
if(front)
s="e"+s;
if(end)
s=s+"e";
我希望这就是你需要的东西
答案 1 :(得分:0)
另一种解决方案
payment.constructor === Promise