Hi,
This is for my wife who's a newbie in
java. Can anyone please help? I am looking for the
java method fully implemented..
"
Problem:
Implement the strstr from string.h in the C standard library. This function is also know as
index in Perl, and
indexOf in Java and JavaScript.
The function should take two
string parameters, short and long (note that these are just the variable names, not types), and return the first occurrence of short in long as a 0 based index into long. If short does not exist in long, the function should return -1.
You should provide a suite of
test data along with your implementation.
Example: if str1=”cap”, str2=”escape”, applying strstr(str1,str2) should return 2
Constraints
You can use Java or C but MUST NOT use high level language facilities such as regular expressions or multi-character string comparisons.
If you choose to implement in C, you may return a char * that points to the character from long where the match begins, or NULL if short is not found.
This should be written as "production quality" code, meaning that it should be code you'd be willing to check in to a production tree. No extraneous debug statements, exit() calls, or anything else that would disturb production code.
The solution should be expressed in a single file with no outside dependencies. It should contain at least one function named strstr that performs the task, and one function named test that returns a true value if the strstr function passes all testcases. You may factor strstr into multiple functions if you like.
"