Advertisement
cbres13

Deleting a character from a string through Index

Feb 13th, 2019
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.53 KB | None | 0 0
  1. ; Purpose: Given a string and a placeholding index, produce the string at where the character at index is removed.
  2.  
  3. ; Signature: String & Number -> String
  4.  
  5. ; Examples:
  6. (check-expect (string-delete "abc" 1) "ac")
  7. (check-expect (string-delete "str" 2) "st")
  8.  
  9. ; Stub:
  10. ;(define (string-delete str index) -1)
  11.  
  12. ; Template:
  13. ; (define (delete-string str index)
  14. ;  (substring ... ... ...)
  15. ;  )
  16.  
  17. ; Code:
  18. (define (string-delete str index)
  19.   (string-append (substring str 0 index)(substring str (+ index 1) (string-length str)))
  20.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement