Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read text as numbers in XML file 2

Status
Not open for further replies.

pandu101

MIS
Sep 20, 2010
17
US
Hello,

I am reading the following line from an XML file. There are several such lines in each XML file. However I only want to capture the bytes from each tag and add up the total bytes. This will tell me how much data was backed up (the XML file is produced by our backup software).

However, I dont know how to read the following line in a way so that I chop off all the characters except the byte count and then store it as an integer. Appreciate your advice. Thanks.

Code:
<new_processed_bytes>Processed 147144589684 bytes in 55 minutes and 2 seconds.</new_processed_bytes>
 



hi,

Something like this?
Code:
  dim MyVar
    MyVar = CVar(Split("<new_processed_bytes>Processed 147144589684 bytes in 55 minutes and 2 seconds.</new_processed_bytes>", " ")(1))


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
A regular expression can parse it out pretty easily.

Code:
'[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/ms974570.aspx[/URL]
'[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/yab2dx62.aspx[/URL]
'[URL unfurl="true"]http://www.regular-expressions.info/index.html[/URL]
set re = new regexp
dim strInput

dim Matches

strInput = "<new_processed_bytes>Processed 147144589684 bytes in 55 minutes and 2 seconds.</new_processed_bytes>"

re.Pattern = "(\d+) bytes"
re.IgnoreCase = true
re.Global = true

if re.Test(strInput) then
    wscript.echo(re.Execute(strInput)(0).SubMatches(0))
else
    wscript.echo("No matches")
end if
 
Thanks Skip - is cvar depracated in vbscript? It does not seem to work and someone mentioned in another forum the cvar is only available in VB but not vbscript! Thanks anyways - learned about the split function.

Jges! You come thru again! :) Thanks for the detailed code and documentation to the MS regex site! I'll give this a try.
 
In VB, the CVar() function is used to convert from the 'variant' data type. In VBScript, everything is a variant; therefore CVar() isn't needed or supported.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top