Micro Focus QTP (UFT) Forums
How to remove extra spaces, tab in a 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 remove extra spaces, tab in a text file? (/Thread-How-to-remove-extra-spaces-tab-in-a-text-file)



How to remove extra spaces, tab in a text file? - kkishore12345 - 12-14-2008

Hi there,
Can one answer my below question please?

I wrote one action and one function as follows. I have clicked associate this function to Action under File Menu
Action:
-----------
Code:
If browser("SPLAT! A Terrestrial RF").Page("SPLAT! A Terrestrial RF").Link("NASA").Exist then
    browser("SPLAT! A Terrestrial RF").Page("SPLAT! A Terrestrial RF").Link("GNU General Public License").Click
    else
    reporter.ReportEvent micDone,"Gne public license", "License page"
end if
Set oFSO=CreateObject("scripting.FileSystemObject")
Set oFile=oFSO.CreateTextFile("C:\temp\another.txt", 2, True)
sCont=browser("SPLAT! A Terrestrial RF").Page("The GNU General Public").Object.documentElement.innertext
ParseSpaces "sCont"
oFile.write sCont
oFile.close
Set oFile=nothing
Set oFSO=Nothing

--------------------

Code:
Function ParseSpaces(TextIn)
   ParseSpaces=Replace(TextIn, " ", "")
   While (Instr(ParseSpaces, " ")>0)
         ParseSpaces=Replace(ParseSpaces, " ","")
   Wend
   While (Instr(ParseSpaces,vbNewLine)>0)
       ParseSpaces=Replace(ParseSpaces, " ", "")
   Wend
   While (Instr(ParseSpaces, vbTab)>0)
       ParseSpaces=Replace(ParseSpaces, " ", "")
   Wend
   While (Instr(ParseSpaces, vbCr)>0)
       ParseSpaces=Replace(ParseSpaces, " ", "")
   Wend
End Function

I am getting invalid parameters and sometime different error. What should I do apart from calling this function? Do I need to make any changes in the setting?

I tried with ParseSpaces(sCont) also, no use.

Please help, its very urgent.
Thanks,
kishore


RE: How to remove extra spaces, tab in a text file? - surya_7mar - 12-14-2008

Code:
ParseSpaces=Replace(ParseSpaces, chr(10),"")
ParseSpaces=Replace(ParseSpaces, chr(14),"")
ParseSpaces=Replace(ParseSpaces, chr(32),"")



RE: How to remove extra spaces, tab in a text file? - kkishore12345 - 12-14-2008

surya_7mar Wrote:ParseSpaces=Replace(ParseSpaces, chr(10),"")
ParseSpaces=Replace(ParseSpaces, chr(14),"")
ParseSpaces=Replace(ParseSpaces, chr(32),"")

Thanks for your reply Surya, I am able to remove couple of spaces, tabs. How can I remove any number of empty spaces in a line?
say for example, I have the following string.
Example:"Testing should be done everywhere.
In the above line, after everywhere, rest of the line is blank. How can I remove these kinds of spaces?

Thanks,
kishore


RE: How to remove extra spaces, tab in a text file? - sreekanth chilam - 12-14-2008

HI Kishore ,

For returning a string without Trailing & Leading Blank spaces can be done by using "Trim" built in function.
( i.e Rtrim,Ltrim,Trim)

Code:
str= "     hai"   ; ltrim(str) --> "hai"

str= "hai    "    ; rtrim(str) --> "hai"

str= "   hai     " ; trim(str) ---> "hai"
If your question is regarding the eliminating leading & trailing blank spaces then , the above solution might be useful to u.


RE: How to remove extra spaces, tab in a text file? - surya_7mar - 12-16-2008

You can Use Trim () which will trim all the spaces


RE: How to remove extra spaces, tab in a text file? - kkishore12345 - 01-04-2009

I used your answers and got the result. Thanks for the support!