如何從字串中移除特定字元。


以下示例展示瞭如何藉助 removeCharAt(string, position) 方法從字串特定位置移除字元。

示例

線上示例

public class Sample {
   public static void main(String args[]) {
      String str = "this is Java";
      System.out.println(removeCharAt(str, 3));
   }
   public static String removeCharAt(String s, int pos) {
      return s.substring(0, pos) + s.substring(pos + 1);
   }
}

輸出

this is Java

更新日期:2020 年 6 月 18 日

242 次瀏覽

開拓你的事業

完成課程獲取認證

開始
廣告
© . All rights reserved.