Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the end of a string, starting from a given pattern?

Tags:

Let's say I have a string like this:

var str = "/abcd/efgh/ijkl/xxx-1/xxx-2"; 

How do I, using Javascript and/or jQuery, remove the part of str starting with xxx, till the end of str?

like image 839
user765368 Avatar asked Jun 08 '12 03:06

user765368


People also ask

How do you remove the end of a string in Python?

The strip functions are strip(), lstrip(), and rstrip(). They remove characters from both ends of a string, the beginning only, and the end only. Python strip() can also remove quotes from the ends of a string. You may have white spaces that you want to remove from the ends of the string.

How do you cut the last letter of a string?

To remove the last character from a string in JavaScript, you should use the slice() method. It takes two arguments: the start index and the end index. slice() supports negative indexing, which means that slice(0, -1) is equivalent to slice(0, str.


1 Answers

str.substring( 0, str.indexOf( "xxx" ) ); 
like image 145
Will Avatar answered Oct 14 '22 04:10

Will