Venelin
Venelin

Reputation: 3306

How to remove symbol and everything after this symbol from a string

Guys i want to know how can i remove a symbol and everything after that symbol from a string with jQuery or JavaScript.

Here is my code:

var optionValueText = $.trim($('[data-divNumber="on"] :selected').text());

The variable optionValueText is printing results like My first result +24.00 euros

So what i want to do is to remove everyting after the + plus symbol including the plus symbol itself.

So for final result of my example i want to receive a result like this My first result and that is it!

How can i make it?

Thanks in advance!

Upvotes: 1

Views: 86

Answers (1)

Pratik Joshi
Pratik Joshi

Reputation: 11693

Working Fiddle

Use

optionValueText = optionValueText.substring(0, optionValueText.indexOf('+'));
alert(optionValueText);

Explanation : Find index(character position) of + and take substring from 0 till that index of + .

For more info read here

Upvotes: 2

Related Questions