删除字符串的某个字符Java

删除字符串的某个字符-Java

    @Test
    public void test02() {
    
    
        // 删除字符串的某个字符
        String str = "Hello world";
        String s = removeCharAt(str, 3);
        System.out.println(s);

        // 删除字符串的几个字符
        String s1 = removeCharAt(str, 2, 4);
        System.out.println(s1);
    }

    public static String removeCharAt(String str, int pos) {
    
    
        return str.substring(0, pos) + str.substring(pos+1);
    }

    public static String removeCharAt(String str, int start, int end) {
    
    
        return str.substring(0, start) + str.substring(end);
    }

Helo world
Heo world

Supongo que te gusta

Origin blog.csdn.net/E_chos/article/details/114641084
Recomendado
Clasificación