|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



STRING METHODS



Vera provides a set of general methods to handle hidden values within string variables.

len() : The len() function returns the length of the string as an integer.
getc() : The getc() function returns an integer that is the ASCII equivalent to the character at specified location.
tolower() : The tolower() function changes upper case characters in a string to lower case, and returns this new string.
toupper() : The toupper() function changes lower case characters in a string to upper case, and returns this new string.
putc() : The putc() task assigns a given character to a specified location.
get_status() : The get_status() function returns the current status flag value as an integer.
get_status_msg(): The get_status_msg() function returns a string describing the current status flag value.
compare() : The compare() function compares two strings to determine if they are identical or not. The comparison is case sensitive . If the strings are identical, a 0 is returned.
icompare() : The icompare() function is the same as compare() except that case is ignored. If the strings are identical, a 0 is returned. A non zero value is returned if they are not identical.
hash() : The hash() function hashes (or encodes) the string and returns a non-negative integer that is less than the size specified.
substr() : The substr() function returns the sub-string of characters between two specified locations.
search() : The search() function searches for a pattern in the string and returns the integer index to the beginning of the pattern.
match() : match() processes a regular expression pattern match.
prematch() : prematch() returns the string before a match, based on the result of the last match() function call.
postmatch() : postmatch() returns the string after a match, based on the result of the last match() function call.
thismatch() : thismatch() returns the matched string, based on the result of the last match() function call.
backref() : backref() returns matched patterns, based on the last match() function call.
atoi() : atoi() returns the integer corresponding to the ASCII decimal representation of a string.
itoa() : The itoa() task converts an integer to an ASCII number in a string.
atooct() : atooct() handles a string as an ASCII octal number and converts it to a bit value.
atobin() : atobin() handles a string as an ASCII binary number and converts it to a bit value.



EXAMPLE : string
program main{
string str,str_1,str_2;
str = "This is a string";
str_1 = str ;
printf("String length = %0d\n", str.len() );//
printf ("The fourth character is the letter %c.\n", str.getc(3) );
printf ("Lower case string is $s \n",str.tolower() );
printf ("Upper case string is $s \n",str.toupper() );
str.putc(0, "1");
printf (" Str after put 1 at 0 loc is %s \n",str);
printf (" Comparing str and str_1 resulted %d \n",str.compare(str_1) );
printf (" Substring from 2 to 4 of str is %s\n",str.substr(2,4) );
printf (" searching for 'is a' in str resulted in %d",str.search("is a") );
printf (" matching for 'is' in str resulted in %d",str.match("is") );
str_2 = "123";
printf ("After execute string.atoi method = %d\n",str_2.atoi() );


}

RESULTS

String length = 16
The fourth character is the letter s.
Lower case string is this is a string
Upper case string is THIS IS A STRING
Str after put 1 at 0 loc is 1his is a string
Comparing str and str_1 resulted 0
Substring from 2 to 4 of str is is
searching for 'is a' in str resulted in 5
matching for 'is' in str resulted in 1
After execute string.atoi method = 123

Index
Introduction
Data Types
Linked List
Operators Part 1
Operators Part 2
Operators Part 3
Operator Precedence
Control Statements
Procedures And Methods
Interprocess
Fork Join
Shadow Variables
Fork Join Control
Wait Var
Event Sync
Event Trigger
Semaphore
Regions
Mailbox
Timeouts
Oop
Casting
Randomization
Randomization Methods
Constraint Block
Constraint Expression
Variable Ordaring
Aop
Predefined Methods
String Methods
Queue Methods
Dut Communication
Functional Coverage

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright 2007-2017 :: all rights reserved www.testbench.in::Disclaimer