Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  136] [ 1]  / answers: 1 / hits: 19231  / 13 Years ago, thu, august 11, 2011, 12:00:00

I'm trying to figure out how to do the following with javascript:

If a substring is in the string, remove from the beginning of the substring till the end of the string from the string.



For example (pseudocode):



var mySub = 'Foo'
var myString = 'testingFooMiscText'
var myString2 = 'testingMisctext'

var myStringEdit = //myString - (Foo till end myString)
var myString2Edit = myString2 //(cause no Foo in it)

More From » replace

 Answers
119
var index = str.indexOf(str1);
if(index != -1)
str = str.substr(index)

[#90663] Wednesday, August 10, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turnerf

Total Points: 620
Total Questions: 101
Total Answers: 109

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
;