How to deal with a string with comma in it from a csv, when we have to read the data by using loadrunner?

試著忘記壹切 提交于 2020-01-03 03:32:08

问题


When I used Loadrunner, it can read data from a csv file. As we know , csv file is separated by a comma.

The question is, if the parameter in csv has comma itself, the string will be separated to several segments. That is not I want to get.

How can we get the original data with comma in it?


回答1:


When data has a comma, use an escape character to store the data in the parameter. For example, if the name is 'Smith, John', it can be stored as Smith\, John in the Loadrunner data file.




回答2:


When you save a file in Excel that has commas in the actual cell data, the whole cell will be inside two " characters. Also it seems that cells with a space in them are inside " chars.

Example

ColA,ColB,"ColC with a , inside",ColD,ColE

More info on CSV file format: http://www.parse-o-matic.com/parse/pskb/CSV-File-Format.htm

The answer to the question is that perhaps the easiest way to do deal with , separators is to change the separator to a ; character. This is also a valid separator in CSV files.

Then the example would be:

ColA;ColB;"ColC with a , inside";ColD;ColE



回答3:


Maybe the right way is to use C functions to read data from the file (for example fopen/fread)? When you have read it you be able to use "strchr" to find first quotes char and second quotes char. All in that interval would be a value, and it doesn't matter if comma is inside. For the documentation about fopen, fread,strchr, you could refer to the HP or C function references. Hope this will help you.




回答4:


Assuming you are reading from a data file for the parameters, just use a custom seperator. Comma is the default, but you can define it to be whatever you want. Whenever I have a comma in the variable data I tend to use a pipe symbol, '|' as a way to distinguish the columns of data in the data file.

Examine your parameter dialog carefully and you will see where to make the change.



来源:https://stackoverflow.com/questions/12793718/how-to-deal-with-a-string-with-comma-in-it-from-a-csv-when-we-have-to-read-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!