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.

2
  • try string1.split("=")[1] Commented Jun 11, 2014 at 7:00
  • You want to split a string ON a particular character, not after it. Commented Feb 10, 2017 at 3:02

4 Answers 4

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"

Sign up to request clarification or add additional context in comments.

Comments

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()

7 Comments

why not just use split?
@sabithpocker What bothers you in using .substring() ..?
@RajaprabhuAravindasamy may be that's something you should ask yourself once you get free :)
@downvoters - why the answer is downvoted. it is right.
@sabithpocker Sorry man.. i just got tempered because here my co-workers teased me because i got a dV..! :) I appreciate your openness.!
|
5

use Split method to split the string into array

demo

var string1= "Hello how are =you";

alert(string1.split("=")[1]);

Comments

1

Use .split() in javascript

var string1= "Hello how are =you";

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

Demo

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.