How to scan for flags in a string, removing them, and processing each one.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eragon
    Contributor
    • Mar 2007
    • 431

    #1

    How to scan for flags in a string, removing them, and processing each one.

    I am creating an Ajax/PHP based console-type-thing, where basically the user enters a command at the prompt, it gets sent to a PHP script to get chewed up and processed, and a string of crap comes back out to be displayed.

    I would like to know if anyone knows a nifty way in Javascript that I can check if certain flags are present in the return from the server, known as the variable req.responseTex t.

    Some examples:

    Code:
    // Server Returns:
     <br />{p}Please enter your password:
    
    // Java should see the {p} as a flag, and the equivalent should occur:
    document.getElementById("input").type='password'; // Line 1
    output = "Please enter your password:"; // Line 2
    
    // As you see, I need several lines similar to the first to execute 
    //   whenever a flag is found, and multiple flags should each work, 
    //   such as {c}{p}.
    // I would also like to be able to use paramaters, such as:
    {m=location_mapped, 90, 100}Server Return Text
    
    // So that it would process if the flag was "m" with three parameters equal to location_mapped, 90, and 100.
    Any help is greatly appreciated.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You may be better off with XML or JSON.

    You can use some of the String methods to grab the flags, e.g. split(), or match() with a regular expression, or even get character by character with charAt().

    Comment

    Working...