Standard String Library functions in string.h in C

FUNCTION USE
strlen Finds the length of the string.
strlwr Converts string to lower case.
strupr Converts string to upper case.
strcat Appends one string at end of another.
strncat Appends first n characters of a string at end of another.
strcpy Copies a string to another.
strncpy Copies first n characters of a string into another.
strcmp Compares two strings
strncmp Compares first n characters of two strings.
strcmpi Compares two strings without regards to case.
stricmp Compares two strings without regards to case.
strnicmp Compares first n characters of a string without regards to case.
strdup Duplicates a string.
strchr Finds first occurrence of a given character in a string.
strrchr Finds last occurrence of a given character in a string.
strstr Finds first occurrence of a given string in a string.
strset Sets all characters of a string to given character.

 

strnset Sets first n characters of a string to given character.
strrev Reverses the string.
   

Why not to use Strings in Cucumber

Cucumber allows you to define step definitions using strings instead of regular expressions.

This might seem simpler at first, but it has other problems, which I’ll illustrate with an example.

Here is a step definition that uses a plain string.

Given “I have 100 in my Account” do

end

We couldn’t write $100 here, because the $ has a special meaning when you define step definitions with strings.

Any $ signs—including any letter or number following it—will be interpreted as an argument, .

This step definition uses an argument:

Given “I have $amount in my Account” do |amount|

 

end

This step definition would match both of the following Gherkin steps:

Given I have 100 in my Account

Given I have $100 in my Account

 

In the first case, the Step Definition’s amount argument would have the value “100”. In the second case it would have the value “$100”. If our Step Definition expects a string with only digits, this can be problematic. We have no way to enforce a consistent way to write Gherkin steps, and the step definitions have to anticipate many kinds of input.

 

This is why using strings instead of regular expressions is not as advantageous as you might think. They give far less control over what gets matched and what arguments a step definition can receive.