Js string engine

From DreamsteepWiki

Jump to: navigation, search

FUNCTION TO PROCESS STRINGS IN JAVASCRIPT

<html>
<body>
<script type="text/javascript">


      var response=new Array(
        "GetFeatureInfo results:",
        "                       ",
        "Layer 'taxpolyswms'" ,
        "  Feature 3934:",
        "    ACCTNODASH = '0123456789123'",
        "    ACREAGE = '0'",
        "    LEGAL1JAD = 'LOT foo8 TROTTI'",
        "    LEGAL2JAD = ''",
        "    LEGAL3JAD = ''",
        "    HOUSENOJAD = '0'",
        "                       ",
        "    STREETJAD = ''",
        "    SITUSZIPJA = ''",
        "    OWNER1JAD = 'JASPER CITY OF'",
        "    OWNER2JAD = ''",
        "    ADDR2JAD = 'P O BOX 12345 '" ,
        "    STATEJAD1 = 'TXS'",
        "                       "
      ) ;



function format_text_response( INPUT_TEXT)
{
      ////////////////////////////////////////////////////////

      SPLITCHAR = "="; //"trigger" character to identify lines to use and to locate split on each line
      var OUTPUTARRAY =new Array() //THIS IS THE STORAGE FOR THE SORTED OUTPUT

      //this loops through the array
      for (var test in INPUT_TEXT)
      {
        //this iterates the array
        var curline = INPUT_TEXT[test] ;
        //this checks it for an equal sign
        lookforequals =  curline.match("=")  ;
        //this splits it in half
        var buffersplit = curline.split(SPLITCHAR)  ;

        //IF AN EQUAL SIGN IS PRESENT IN LINE LOOK AT RIGHT AND LEFT SIDE , IGNORE ALL OTHERS
        if (lookforequals == "=") //or null
        {
         OUTPUTARRAY.push ( (buffersplit[0]+" "+buffersplit[1]  ) );
         //debug  - or to output it to html document
         //document.write( ("<p>"+(buffersplit[0]+" "+buffersplit[1]  )+"</p>") );
        }

      }//end of loop

      return OUTPUTARRAY;

} //end of function


////

alert(format_text_response(response));



</script>
</body>
</html>

Personal tools