I am currently working on a JavaScript function that will remove specific characters from a string. I have tried various methods such as `string.slice()`, `string.substr()`, and `string.substring()`, but what I really need to do is remove everything before a colon ':'.
The challenge is that the length of the person's name is not fixed.
The desired outcome should be:
- this is test text1
- this is test text2
- this is test text3
- this is test text4
Sometimes, the text might look like: "Qt: john: when i said .... she: not again", in which case the desired result would be: "when i said .... she: not again". I only want to remove anything entered after "Qt: name:".
function myFunction() {
var a="Qt: joe: this is test text1";
var b="Qt: bella: this is test text2";
var c="this is test text3";
var d="Qt: alex: this is test text4";
removetxt(a);
removetxt(b);
removetxt(c);
removetxt(d);
}
function removetxt(x){
if (x.slice(0,2) == 'Qt'){
console.log("found Qt");
} else {
console.log(x);
}
}