2010-09-03 14 views
0

Je dois vérifier la valeur d'une variable particulière seule à partir ensemble de variables en utilisant JQuery .....Comment diviser un mot d'une phrase en utilisant JQuery

C'est mon code

return "{" + string.Format("IsPreviewed:'{0}',PreviewdUrl:'{1}',IsFreeVideo:'{2}'", 
          parameters[12],pranu,jithu) +"}"; 

La valeur sera renvoyée à une fonction dans un fichier .Js pour ex: uploader.Js où je stockerai toutes ces valeurs dans une variable.

De cette variable que je dois vérifier si la variable Pranu contient une valeur comme www.google.com, variable jithu a une valeur booléenne true ou false en utilisant JQuery

Peut-on fournir des idées ou le codage de l'échantillon Pour m'aider à résoudre cette tâche ......

Répondre

2

Donc, si j'ai bien compris, vous voulez juste sortir la variable pranu de la chaîne?

var foo = "IsPreviewed:'1',PreviewdUrl:'www.google.co.uk',IsFreeVideo:'y'"; 

var variable = "PreviewdUrl"; 

// Get the start of the string, add 2 to gnore the preceeding :' 
var startIndex = foo.indexOf(variable) + variable.length + 2; 
var endIndex = foo.indexOf(",", startIndex) - 1; // Remove the end ' 

alert(foo.substring(startIndex, endIndex)); 

Voici un working example.

+0

NB. Il y a probablement une meilleure méthode utilisant regex. – GenericTypeTea

Questions connexes