Micro Focus QTP (UFT) Forums
How to retrieve specied string from text file - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to retrieve specied string from text file (/Thread-How-to-retrieve-specied-string-from-text-file)



How to retrieve specied string from text file - nsuresh316 - 06-08-2015

I have a txt file content is as follows
Code:
10.76.34.61    10.76.177.138    NULL    POST    /a2asoa/v2008/001/Security.asmx    <REQ><OP>IsUserIdAvailable</OP><SOAP><userID>shawnandersonxnet</userID><pwd>****</pwd><sourceid>1012</sourceid><searchUserID>cwclvickers1</searchUserID><languageID>1</languageID></SOAP></REQ>    16    4000    200    0    931    931    NULL    89998    1    2015-06-03 14:26:17.257    3000    137580    0
10.76.34.61    10.76.177.138    NULL    POST    /a2asoa/v2008/001/Security.asmx    <REQ><OP>GetSecLevelsFunctions</OP><SOAP><userId>shawnandersonxnet</userId><pwd>****</pwd><sourceid>1012</sourceid><searchSecLevels>17497</searchSecLevels><showInactiveSecLevels>0</showInactiveSecLevels><template>0</template><languageId>1</languageId></SOAP></REQ>    125    4000    200    0    1905    1905    NULL    91168    1    2015-06-03 14:33:10.350    3000    137580    0
10.76.34.223    10.76.177.141    NULL    POST    /a2asoa/v2008/001/Notifications.asmx    <REQ><OP>GetClientConfig</OP><SOAP><sourceid>346</sourceid><userid>budcsa</userid><pwd>****</pwd><msgType>EMAIL</msgType><cardNumber>******7507804998</cardNumber><clientid></clientid><programid></programid><subProgramid></subProgramid></SOAP></REQ>    16    1000    200    0    958    958    NULL    72264    1    2015-06-03 07:58:27.657    1000    659    0
10.76.34.161    10.76.177.141    NULL    POST    /a2asoa/v2008/001/Security.asmx    <REQ><OP>GetSecLevelsFunctions</OP><SOAP><userId>shawnandersonxnet</userId><pwd>****</pwd><sourceid>1012</sourceid><searchSecLevels>2732,2732</searchSecLevels><showInactiveSecLevels>0</showInactiveSecLevels><template>0</template><languageId>1</languageId></SOAP></REQ>    94    4000    200    0    841    841    NULL    37690    1    2015-06-03 15:26:35.080    3000    137580    0
10.76.34.61    10.76.177.138    NULL    POST    /a2asoa/v2008/001/Client.asmx    <REQ><OP>GetAuthorizedClientTree</OP><SOAP><userId>shawnandersonxnet</userId><pwd>****</pwd><sourceid>1012</sourceid><clientId></clientId><clientNamePattern></clientNamePattern><startRow></startRow><stopRow></stopRow><languageId>1</languageId></SOAP></REQ>    7781    3500    200    0    1905    1905    NULL    94484    1    2015-06-03 15:26:49.083    3000    137580    0

From this file i want to retrieve the value from the element sourceid
for Eg.
Code:
<sourceid>1012</sourceid> From this i want 1012 alone



RE: How to retrieve specied string from text file - nsuresh316 - 06-09-2015

Hi Team, I found the solution
Sample.txt contains the above content
Code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set objTxtFile = FSO.OpenTextFile("C:\Users\Suresh\Desktop\sample.txt")
i=0
Do Until objTxtFile.AtEndOfStream
sContent = objTxtFile.ReadLine
sContent= replace(sContent,"<sourceid>","sourceid=")
sContent= replace(sContent,"</sourceid>","@sourceid")
a=instr(sContent,"=")
a=a+1
b=instr(sContent,"@")
c=b-a
sContent=Mid(sContent,a,c)
print sContent
i = i+1
Loop
Hope it will help someone