0

Lets say i have the following string:

var myString = "hello and welcome to my website";

Is there any function in Javascript to extract the part starting from a given substring?

For exemple:

var newString = extractString(myString, "welcome");

And newString will be "welcome to my website".

1 Answer 1

4

Here you go

> myString = "hello and welcome to my website"
"hello and welcome to my website"
> part = myString.substr(myString.indexOf("welcome"))
"welcome to my website"

Note that this assumes the substring to be there, if this might not be the case, add a check:

var i = myString.indexOf(search)
if(i >= 0)
   ...ok
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.