node.js - Remove substring (URL) from a string (URL) with javascript -


i having problems removing baseurl url.

i have string

var baseurl = 'https://www.stackoverflow.com'; var url = 'https://www.stackoverflow.com/test/number/'; url.replace(baseurl, "");  

now expect result /test/number/ not remove first part of string.

the code example. not know sure if baseurl substring cannot cut length.

any ideas?

you need update string returning value of string#replace method since method won't updates string.

var baseurl = 'https://www.stackoverflow.com';  var url = 'https://www.stackoverflow.com/test/number/';  url = url.replace(baseurl, "");    console.log(url);


using string#substring , string#indexof methods.

var baseurl = 'https://www.stackoverflow.com';  var url = 'https://www.stackoverflow.com/test/number/';  var = url.indexof(baseurl);  url = url.substring(0,i) + url.substring(i + baseurl.length);    console.log(url);


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -