String/Text functions 4 (WinRunner, TSL)

Categories: Source codeText Data

Parent page: Service Functions – String / WinRunner

Find a substring defined by 2 tokens

public function str_get_text(in s, in text_before, in text_after) {
 auto index1, index2;
 auto result;
 if (text_before == "")
 index1 = 1;
 else 
 index1 = index(s, text_before);
 if (index1 == 0)
 return("");
 else 
 index1 = index1 + length(text_before);
 if (text_after == "")
 index2 = length(s)+1;
 else 
 index2 = index(s, text_after);
 if (index2 == 0)
 index2 = length(s);
 else 
 index2 = index2 - index1;
 result = substr(s, index1, index2);
 return(result);
}

Return substring by index

public function str_get_token(in s, in idx, in separator) {
 auto dtArray[];
 if (s == "") return("");
 split(s, dtArray, separator);
 return(dtArray[idx]);
}

Split filepath - return folder path, file name and extension separately

public function str_fsplit(in fspec, inout _fspec[]) {
 auto i, elements, fname, fpath, path_array[];
 elements = split (fspec, path_array, "\\");
 fpath = path_array[1];
 for (i=2;i<elements;i++)
 fpath = fpath & "\\" & path_array[i];
 if (elements > 1)
 fpath = fpath & "\\";
 else 
 fpath = "";
 _fspec["path"] = fpath;
 fname = path_array [elements];
 elements = split (fname, path_array, ".");
 if (elements > 1)
 _fspec["ext"] = path_array [elements];
 fname = path_array[1];
 for (i=2;i<elements;i++)
 fname = fname & "." & path_array[i];
 _fspec["name"] = fname;
 return(E_OK); 
}


  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.