How to remove part of a string?

后端 未结 7 1555
夕颜
夕颜 2020-11-30 23:16

Let’s say I have test_23 and I want to remove test_.

How do I do that?

The prefix before _ can change.

7条回答
  •  天命终不由人
    2020-11-30 23:49

    If you want to remove part of string

    let str = "test_23";
    str.replace("test_", "");
    // 23
    

    If you want to replace part of string

    let str = "test_23";
    str.replace("test_", "student-");
    // student-23
    

提交回复
热议问题