![ContractedBlock.gif](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
function
GetValueByKey(strs, key, sp)
{
key = key.toLowerCase();
strs = strs.toLowerCase();
if (strs.indexOf(key + " = " ) > - 1 )
{
var result;
var s = strs.substring(strs.indexOf(key + " = " ));
if (s.indexOf(sp) != - 1 )
{
result = s.substring(s.indexOf(key + " = " ) + key.length + 1 , s.indexOf(sp));
} else
{
if (s.indexOf(key + " = " ) != - 1 )
{
result = s.substring(s.indexOf(key + " = " ) + key.length + 1 );
}
}
}
return result;
}
// var strs = "A=1,B=2,c=3,d=4,ee=";
// document.write( GetValueByKey(strs, "B", ","));
-- value 2
{
key = key.toLowerCase();
strs = strs.toLowerCase();
if (strs.indexOf(key + " = " ) > - 1 )
{
var result;
var s = strs.substring(strs.indexOf(key + " = " ));
if (s.indexOf(sp) != - 1 )
{
result = s.substring(s.indexOf(key + " = " ) + key.length + 1 , s.indexOf(sp));
} else
{
if (s.indexOf(key + " = " ) != - 1 )
{
result = s.substring(s.indexOf(key + " = " ) + key.length + 1 );
}
}
}
return result;
}
// var strs = "A=1,B=2,c=3,d=4,ee=";
// document.write( GetValueByKey(strs, "B", ","));
-- value 2