Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- * Deletes all invalid characters starting from last valid one
- * valid characters passes the 'test_char' function
- *)
- let trim w =
- let rec aux ww =
- match ww with
- | [] -> []
- | h :: t -> if test_char h then List.rev (h :: t) else aux t
- in
- aux (List.rev w)
- ;;
- (* Testing, let's say we accept just a-z A-Z *)
- trim ['c', 'b', 'd', '!', '$'];; (* outputs: ['c', 'b', 'd'] *)
- trim ['c', '$', 'd'];; (* outputs: ['c', '$', 'd'] *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement