A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Strip out part of node

  1. #1
    Member
    Join Date
    May 2008
    Posts
    70

    Strip out part of node

    Hello, I'm struggling to strip out the word 'Section' from a text box that loads from xml.

    for(i=0; i<xmlNode.childNodes[1].childNodes[0].childNodes.length; i++)
    if(xmlNode.childNodes[1].childNodes[0].childNodes[i].nodeName == "sections")
    sectNo = xmlNode.childNodes[1].childNodes[0].childNodes[i].firstChild;

    section_txt.text += sectNo;

    When the node 'sections' returns 'Section 12' how can I strip out the word 'Section' and only have '12' load into the section_txt box?

    Any help would be much appreciated

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    use

    Actionscript Code:
    myVar = "Section 12";
    myNewVar = myVar.substring(8,myVar.length);
    trace(myNewVar);

    gparis

  3. #3
    Member
    Join Date
    May 2008
    Posts
    70
    Thanks gparis, That has posed another problem in that the node will return Sections 1 to 22 depending on which xml gets loaded. Is there a way of stripping 'section' out of all of them or do i need to myVar for each one?

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    the substring strips the first 7 characters, ie: 'section ' *including the space after the word. Then gives you everything after these. You could turn this into a function:

    function strip7 (myVar) {
    return myVar.substring(8,myVar.length);
    }

    so with anything, you can say strip7(anything)

    Full example:
    Actionscript Code:
    function strip7 (myVar) {
    return myVar.substring(8,myVar.length);
    }

    anything = "Section 123";

    trace(strip7(anything));

    gparis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center