Java example - to delete a character string
The following examples, we () function to delete a character string by string functions substring, we will encapsulate the functionality in removeCharAt function.
Examples of code is as follows:
//Main.java 文件 public class Main { 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); } }
The output is the above code examples:
thi is Java