8

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
  • 58,730
  • 15
  • 91
  • 116
deepak.mr888
  • 349
  • 2
  • 11
  • 26

4 Answers4

21

Demo Fiddle

Use JS split function: 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,588
  • 10
  • 46
  • 79
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
  • 66,513
  • 17
  • 101
  • 130
5

use Split method to split the string into array

demo

var string1= "Hello how are =you";

alert(string1.split("=")[1]);
Balachandran
  • 9,567
  • 1
  • 16
  • 26
1

Use .split() in javascript

var string1= "Hello how are =you";

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

Demo

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49