Just wandering how can I replace word update, insert and delete from string in jquery?
I'm using the following script to do it, just wandering do there have any better way instead of this?
string a = "Update the person, update then delete the person, insert the message";
a.toUpper().replace("UPDATE", "").replace("DELETE","").replace("INSERT", "");
OUTPUT: the person, then the person, the message
You can use a regex. Match UPDATE, DELETE or INSERT followed by optional white space, g means global to replace all instances, not just the first and i is case insensitive.
let a = "Update the person, update then delete the person, insert the message"; console.log(a.replace(/(UPDATE|DELETE|INSERT)\\s?/gi, ""));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.