Remove part of string in Java

后端 未结 12 1743
遥遥无期
遥遥无期 2020-11-28 04:22

I want to remove a part of string from one character, that is:

Source string:

manchester united (with nice players)

Target string:

12条回答
  •  庸人自扰
    2020-11-28 05:10

    // Java program to remove a substring from a string
    public class RemoveSubString {
    
        public static void main(String[] args) {
            String master = "1,2,3,4,5";
            String to_remove="3,";
    
            String new_string = master.replace(to_remove, "");
            // the above line replaces the t_remove string with blank string in master
    
            System.out.println(master);
            System.out.println(new_string);
    
        }
    }
    

提交回复
热议问题