当前位置: 代码迷 >> JavaScript >> javascript中字符串处理有关问题,需解答,待
  详细解决方案

javascript中字符串处理有关问题,需解答,待

热度:132   发布时间:2012-02-27 10:00:22.0
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>
  相关解决方案