viernes, 23 de abril de 2010

JavaScript: getVariable GetExtension

html = "w1=0.23&w2=0.29&error=0";

error = getVariable(html,"error");

function getVariable(html, variable)
{
if ( html.indexOf(variable) < 0 ) return "-1";

var resultado = "-1";

var parts = html.split("&");
var cant = parts.length;

for ( i = 0; i < cant; i++)
{
str = parts[i];
if ( str.indexOf(variable) != -1 ) //parts[i] == variable )
{
var word = str.split("=");
resultado = word[1];
//alert("encontre");
break;
}
}

return resultado;
}

function GetExtension(Filename) {
var I = Filename.lastIndexOf(".");
return (I > -1) ? Filename.substring(I + 1, Filename.length) : "";
}

No hay comentarios:

Publicar un comentario