-
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
-
use
Actionscript Code:
myVar = "Section 12"; myNewVar = myVar.substring(8,myVar.length); trace(myNewVar);
gparis
-
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?
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|