6

Here is my code :

var string1= "Hello how are =you";

I want a string after "=" i.e. "you" only from this whole string. Suppose the string will always have one "=" character and i want all the string after that character in a new variable in jquery.

Please help me out.

Florian Margaine
  • 54,552
  • 14
  • 89
  • 116
deepak.mr888
  • 329
  • 2
  • 11
  • 26

4 Answers4

18

Demo Fiddle

Use this : jQuery split(),

var string1= "Hello how are =you";
string1 = string1.split('=')[1];

Split gives you two outputs:

  • [0] = "Hello how are "

  • [1] = "you"

Shaunak D
  • 20,236
  • 10
  • 45
  • 76
6

Try to use String.prototype.substring() in this context,

var string1= "Hello how are =you"; 
var result = string1.substring(string1.indexOf('=') + 1);

DEMO

Proof for the Speed in execution while comparing with other answers which uses .split()

Rajaprabhu Aravindasamy
  • 64,912
  • 15
  • 96
  • 124
5

use Split method to split the string into array

demo

var string1= "Hello how are =you";

alert(string1.split("=")[1]);
Balachandran
  • 9,427
  • 1
  • 14
  • 25
1

Use .split() in javascript

var string1= "Hello how are =you";

console.log(string1.split("=")[1]); // returns "you"

Demo

Sudharsan S
  • 15,058
  • 3
  • 28
  • 49