I have a string, and I want to remove a specific segment from it. The situation is as follows:
var input: string = "Quick brown fox jumped on lazy dogs."; Var scratch start: number = input Index ("br"); Var scratch: Number = input.indexoff ("la"); Var output: string = input. Substring (0, scrubstart) + input. Substring (scrubEnd, input.length); I set it this way because the input text is different every time, and the section I want to remove is at a different location all the time, but the contents of this section are the same.
The code I have not worked for, and it gives everything after the scrub start. Where did I go wrong?
The code from your question works as expected, resulting in:
Quick Lazy Dogs
This can be accomplished either by using string methods.
Slice: const input: string = "Quick brown fox jumped on lazy dogs."; Var output: string = input. Slice (0, input.indexoff ("br") + input.slice (input.indexOf ("la")); substrings: const input: string = "quick brown fox jumped on lazy dogs."; Var output: string = input. Substring (0, input.indow ("br") + input. Substring (input.indexOf ("la")); Reggae:
You can also apply regular expressions; However, by the patterns instead of the index.
const input: string = "quick brown fox jumped on lazy dogs."; Var Pattern: RegExp = /brown.en?the/; Var output: string = input.replace (pattern, "");
No comments:
Post a Comment