我正在試驗字符串和字符串替換,例如在應用程序中從字符串去除不良語言或惡意代碼字符。這是工作,但在編譯時輸出的輸出之前,留下了很大的空間「中傷管理......」我如何刪除變量的代碼輸出中的大領先空間
//import java.util.regex.Pattern;
class grandaddy {
public static void main (String [ ] args) {
//"now that the k's in place where the c used to be" (now it's on)
String tempinvarate= "marduk";
String sminth= "subparticle";
String infiltrate= "cosmicwind";
tempinvarate=tempinvarate.replace ("k", "c");
String a= "piss shit [email protected]£$%^* vilification managed";
String b=" by mark scorfield";
a= a.replace("piss", "");
a= a.replace("shit", "");
a= a.replaceAll("[^a-z-A-Z0-9]", " ");
a=a+b;
System.out.println(tempinvarate);
System.out.println(tempinvarate.replace("k", "c"));
System.out.println(sminth);
System.out.println(sminth.replace("sub", "sminth"));
System.out.println(infiltrate);
System.out.println(infiltrate.replace("cosmic" , "minute"));
//int n = a.length();
//Pattern SPACE = Pattern.compile(" ");
//String[] arr = SPACE.split(a);
//String[] splitStr = a.trim().split("\\s+");
System.out.println(a);
}
}
'String#trim()' –
非常感謝 - 我在發佈之前嘗試過,但是語法錯誤。 –