Converting string characters in QTP
Chris Sharman
chris.sharman@ccagroup.co.uk
Wed, 17 Oct 2001 09:01:09 +0100
> Can any one suggest how to convert commas in a string into another
>character in QTP?
No easy way.
If the goal is to remove embedded commas to create a csv, you can enclose
the string in quotes (although then you have the same problem with the
quotes).
In Powerhouse:
; assuming a length of 80, substituting ";" for ","
def i1 int*4 = index(original, ",")
def str1 char*80 = original if (i1=0) else original[1:i1 -
1]+";"+original[i1+1:80 - i1]
; 1st taken care of ...
def i2 int*4 = 0 if (i1=0) else index(str1,",")
def str2 char*80 = str1 if (i2=0) else str1[1:i2 - 1]+";"+str1[i2+1:80 - i2]
; 2nd taken care of ...
def i3 int*4 = 0 if (i2=0) else index(str2,",")
def str3 char*80 = str2 if (i3=0) else str2[1:i3 - 1]+";"+str2[i3+1:80 - i3]
; 3rd taken care of ...
; continue as long as seems necessary.
Note that this is quite inefficient:
i1 is evaluated 4 times in the evaluation of str1, 5 in the evaluation of i2
(if there's a comma).
Similarly i2 and i3.
For this reason you may get better performance doing multiple passes,
removing 1, or a few, commas each time, rather than trying to remove a large
number of commas in one pass.
Alternatively, you could use TPU (on VMS) or perl, or some similar tool.
Chris
-----------------------------------------------------------------------
Any views expressed in this message are those of the sender and not
necessarily those of CCA Group. The unauthorized use, disclosure,
copying or alteration of this message is forbidden. The contents of
this message may be confidential and/or privileged, copyright CCA Group
and are intended solely for the use of the individual or entity to whom
they are addressed. Whilst this message has been scanned, CCA Group
cannot guarantee that it is virus free or compatible with your systems
and accepts no responsibility for any loss or damage arising from its
use. The recipient is advised to run their own anti-virus software. If
you receive this message in error please contact
postmaster@ccagroup.co.uk immediately, destroy any copies and delete it
from your computer systems.