且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从.csv文件中读取字符串并将其拆分?

更新时间:2023-11-14 22:11:16

好,尝试下面的beanshell(= java)代码将提取的主题字符串"变量解析为单独的主题"变量(来自

Well, try the following beanshell (=java) code to parse extracted "subjects string" variable into separate "subject" variables (from BeanShell Sampler e.g.):

String line = vars.get("vSubjects");

if(line != null) {
    StringTokenizer st = new StringTokenizer(line, ":");

    int i = 0;
    while (st.hasMoreTokens()) {
        String subj = st.nextToken();

        i++;
        String varname = vars.get("vName") + "_subj_" + i;
        vars.put(varname,subj);
    }
}

因此,您将获得每个字符串的解析变量,如下所示(您可以使用调试采样器进行监控):

So you'll get for each string parsed variables like the following (you can use Debug Sampler to monitor):

John_subj_1=Maths
John_subj_2=Science
John_subj_3=History
. . .
vAge=23
vGender=Male
vName=John
vSubjects=Maths:Science:History