日期:2014-05-16  浏览次数:20376 次

javascript中字符串处理问题,急需解答,在线等待
我想用javascript获得如下字符串中

<FIELDS   SDE.CAPITAL.NAME= "±±             "   SDE.CAPITAL.PYNAME= "123 "   #SHAPE#= "[Geometry] "   SDE.CAPITAL.OBJECTID= "658 "   SHAPE.AREA= "0 "   SHAPE.LEN= "0 "   />

字段名的数组,  
name
pyname
objectid
area
len

注意:字段值中,可能存在任何字符串

应该怎么处理...请大家帮帮忙....谢谢.小弟在线等待!!!

------解决方案--------------------
<script language= "javascript ">
<!--
var sourceStr = ' <FIELDS SDE.CAPITAL.NAME= "±± " SDE.CAPITAL.PYNAME= "123 " #SHAPE#= "[Geometry] " SDE.CAPITAL.OBJECTID= "658 " SHAPE.AREA= "0 " SHAPE.LEN= "0 " /> ';

var resultArray = sourceStr.match(/\.([^=\.]+)=/g);
if(resultArray){
for (var i = 0; i < resultArray.length; i++){
resultArray[i] = resultArray[i].substr(1, resultArray[i].length-2);
}
alert(resultArray.join( "\n "));
}
//-->
</script>