Question

I need to separate the values from the following string based on delimiter "," in QTP (CurrentAmount=140,000.00, currency=USD, originalAmount=200,000.00)

I used following code below

splittext= Split (strng, ",")
For i=0 to ubound(splittext)
msgbox splittext(i)
next

Problem here is, output value is something like this

0= CurrentAmount=140
1= 000.00
2= currency=USD.... so on

The code split the following value (CurrentAmount=140,000.00,) into two parts because of the "," in the 140,000.00

I need a code to separate the value based on delimiter "," but should ignore the "," present in the numeric data

Please let me with this issue... Thanks

Was it helpful?

Solution

This should be simple - assuming that there is a space after the required delim comma char. Notice the space after comma used in Split function.

Public Sub Test()
    splitText = Split("CurrentAmount=140,000.00, currency=USD, originalAmount=200,000.00", ", ")
    For i = 0 To UBound(splitText)
        MsgBox splitText(i)
    Next
End Sub

OTHER TIPS

Pankaj Jaju's solution works, assuming you can trust the CSV string to always have spaces after the commas that separate fields. But I think the underlying problem is that the format of the input isn't very clearly specified. If you can change the format, you should get rid of the commas inside the numbers. Alternatively you could escape the commas properly, but then it would be slightly trickier to get the regex right. (And there are varying standards on how to escape commas in CSV format - some systems use \,, others use quotation marks.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top