Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove characters at certain position at string

I want to remove certain characters at specific positions of the String. I have the positions, but I am facing problems removing the characters.

what i am doing is:

if (string.subSequence(k, k + 4).equals("\n\t\t\t")){
    string = string.subSequence(0, k) + "" + s.subSequence(k, s.length());
}

I need to remove "\n\t\t\t" from string

like image 328
Hassaan Rabbani Avatar asked Feb 21 '26 09:02

Hassaan Rabbani


2 Answers

Use StringBuilder:

StringBuilder sb = new StringBuilder(str);

sb.delete(start, end);
sb.deleteCharAt(index);

String result = sb.toString();
like image 101
Zong Avatar answered Feb 22 '26 22:02

Zong


Use StringBuilder

String str="    ab a acd";
        StringBuilder sb = new StringBuilder(str);

        sb.delete(0,3);
        sb.deleteCharAt(0);

        String result = sb.toString();
        System.out.println(result);
like image 28
Meghana Randad Avatar answered Feb 22 '26 21:02

Meghana Randad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!