Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char temp_string;
- int index;
- // Get string length.
- index = strlength(haystack);
- // There's no working strinlast function, so we'll just
- // build our own naive search algorithm here.
- //
- // We create a temporary string from haystack, starting
- // at the far right character. We then use stringinfirst
- // to see if our needle is in the temp_string, and if it
- // is we now have an index to use for strleft.
- //
- // If the result is invalid (-1), then we build the
- // tempstring from haystack, now one character back, and
- // continue until our strinfirst gets a good result.
- do
- {
- index--;
- // Get the right end of haystack, starting
- // from index.
- temp_string = strright(haystack, index);
- } while (strinfirst(temp_string, needle) == -1);
- // Now that we have our index pointing to the last
- // occurrence of needle in haystack, we can use strleft
- // to return the preceding characters.
- return strleft(haystack, index);
Add Comment
Please, Sign In to add comment