Advertisement
0xNOP

CJAM - Find Sub-String in String - (*Two Versions*)

Apr 11th, 2017
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------------------------------------------
  2. Author 0xNOP
  3.  
  4. 1ST Version:
  5. --------------------------------------------------------------------------------------------------------------------------------
  6. "STRING""STR"#"Found!":A "Woops! Nothing Found!":B;;-1>AB? e# Try it out at: https://is.gd/q4527m
  7. --------------------------------------------------------------------------------------------------------------------------------
  8. "STRING" # Pushes String Literal onto the Stack | String to Search
  9. "STR" # Pushes String Literal onto the Stack | String to Find
  10. # # Find Index (returns [index] if found, else returns [-1])
  11. "Found!":A # Store String literal in variable [A]
  12. "Woops! Nothing Found!":B # Store String literal in variable [B]
  13. ;; # Removes Two Top Most items from Stack
  14. -1> # Verifies if the top element from Stack is [-1]
  15. AB # If [-1] then [A] is pushed next, else [B] is pushed instead.
  16. ? # Performs [IF]
  17. --------------------------------------------------------------------------------------------------------------------------------
  18.  
  19. 2ND Version:
  20. --------------------------------------------------------------------------------------------------------------------------------
  21. "STRING""STR"#-1>"Found!""Woops! Nothing Found!"? e# Try it out at: https://is.gd/IyhuX4
  22. --------------------------------------------------------------------------------------------------------------------------------
  23. Code Explanation is basically the same thing as Version 1, the only thing that changes is that variables are not used anymore.
  24. --------------------------------------------------------------------------------------------------------------------------------
  25.  
  26.  
  27. 3RD Version:
  28. --------------------------------------------------------------------------------------------------------------------------------
  29. l:Al:B;;AB#-1>"Found!""Woops! Nothing Found!"? e# Try it out at: https://is.gd/K8WFVE
  30. --------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement