#remove a part from a string
19 messages · Page 1 of 1 (latest)
String.prototype.replace()
The replace() method returns a new string with one, some, or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence will be replaced. The original string is left unchanged.
<string>.replace(“<that stuff>”, “”)
if the number is always changing, use the regex /&s=\d{13}/gm
assuming the number is always 13 long
ah ofc, yh
How would I do it when the number is not always 13 long?
I was just about to ask what each bit did 😂, thanks chewie
remove a part from a string
let url = "https://test.com/en/editor?env=row&lat=24.89479&lon=-53.69694&s=8522367606782&zoomLevel=16";
let modifiedUrl = url.replace(/&s=[^&]*/, "");
or
let url = "https://test.com/en/editor?env=row&lat=24.89479&lon=-53.69694&s=8522367606782&zoomLevel=16";
let startIndex = url.indexOf("&s=")
let endIndex = url.indexOf("&zoomLevel")
let modifiedUrl = url.substring(0, startIndex) + url.substring(endIndex)
Such a shit solution lol
but it works lol
The first one remove too much
And it's just overcomplicating lmao
yeah you right first one removes to mutch /&s=[^&]*/ should do
now its just mine with a different identifier
i wasnt trying to show yours is wrong lol or copie it i use second method myself most of the time for smaller aplicatins as its easyert to debug find issues