共計 317 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Java 中,可以使用 replaceAll() 方法來移除字符串。該方法可以使用正則表達式來指定要移除的字符串。
下面是一個示例代碼:
public class RemoveString {public static void main(String[] args) {String str = "Hello, World!";
String removedStr = str.replaceAll("World", "");
System.out.println(removedStr); // 輸出:Hello, !
}
}
在上面的示例中,我們使用 replaceAll() 方法將字符串中的 "World" 替換為空字符串,從而實現了移除該字符串的效果。
丸趣 TV 網 – 提供最優質的資源集合!
正文完