Guest User

Untitled

a guest
Oct 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. char temp_string;
  2. int index;
  3.  
  4. // Get string length.
  5. index = strlength(haystack);
  6.  
  7. // There's no working strinlast function, so we'll just
  8. // build our own naive search algorithm here.
  9. //
  10. // We create a temporary string from haystack, starting
  11. // at the far right character. We then use stringinfirst
  12. // to see if our needle is in the temp_string, and if it
  13. // is we now have an index to use for strleft.
  14. //
  15. // If the result is invalid (-1), then we build the
  16. // tempstring from haystack, now one character back, and
  17. // continue until our strinfirst gets a good result.
  18. do
  19. {
  20. index--;
  21.  
  22. // Get the right end of haystack, starting
  23. // from index.
  24. temp_string = strright(haystack, index);
  25.  
  26. } while (strinfirst(temp_string, needle) == -1);
  27.  
  28.  
  29. // Now that we have our index pointing to the last
  30. // occurrence of needle in haystack, we can use strleft
  31. // to return the preceding characters.
  32. return strleft(haystack, index);
Add Comment
Please, Sign In to add comment