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


以下示例顯示如何使用 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

更新時間:18-06-2020

242 次瀏覽

開啟你的 職業生涯

透過完成本課程獲得證書

開始吧
廣告
© . All rights reserved.