preload

String/Text functions (WinRunner, TSL)

Posted by Albert Gareev on Mar 14, 2007 | Categories: Source codeText Data

Parent page: Service Functions – String / WinRunner

Trim text line

public function str_trim(in value) {
 auto StringArray[];
 if (length(value) == 0)
  return ("");
#if we have space chars only - let's do it quickly  
 if (index(value,"\t") == 0) {
  if (split(value, StringArray, " ") == 1)
   return(StringArray[1]);
  }
 
 return str_rtrim(str_ltrim(value)); 
}
###

public function str_ltrim(in s) {
   auto i;
   auto src = s;

 for (i=1;i<=length(src);i++)
  if ((substr(src,i,1) != " ") && (substr(src,i,1) != "\t") && (substr(src,i,1) != " ")) # web space char
   break;
  
   return(substr(src, i, length(src)));
}

###
 

public function str_rtrim(in s) {
 auto i;
 auto src = s;

 for (i=length(src);i>0;i--)
  if ((substr(src,i,1) != " ") && (substr(src,i,1) != "\t") && (substr(src,i,1) != " ")) # web space char
   break;
 
 return(substr(src, 1, i));
}

Check format

public function is_alpha(in c) {
   auto ch = ascii(substr(c, 1, 1));

   if ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))
 return(E_OK);
   else
 return(-1);
}

###
 

public function is_digit(in c) {
   auto ch = ascii(substr(c, 1, 1));

   if (ch >= 48 && ch <= 57)
 return(E_OK);
   else
 return(-1);
}

###
 

public function is_number(in v_str) {
 auto rc;

 rc = v_str*(-1)*(-1);
 
 if (rc == v_str)
  return(E_OK);
 else
  return(-1);
}

###
 

public function is_number2(inout v_str) {
# Note: this function is not intended to cover the all possible combinations of "," and "." occurences
 auto rc, sVector[], s, c, i;

# remove ","
 v_str = str_replace(v_str, ",", "");

 rc = v_str*(-1)*(-1);
 
 if (rc == v_str)
  return(E_OK);
 else
  return(-1);
}


  • Leave a Reply

    * Required
    ** Your Email is never shared

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