We're a place where coders share, stay up-to-date and grow their careers.
In F#. Not the most straightforward way to solve this, but I wanted to use the language Array splicing.
let stringToByteArray (s:string)= System.Text.Encoding.ASCII.GetBytes s let byteArraySplice x y (b: byte[]) = b.[x..y] let byteArrayToString (b: byte[]) = System.Text.Encoding.ASCII.GetString b let stringPeeler s = s |> stringToByteArray |> byteArraySplice 1 (s.Length - 2) |> byteArrayToString printfn "%s" <| stringPeeler "abcdefgh" printfn "%s" <| stringPeeler "ab" printfn "%s" <| stringPeeler "a"
And it turns out that you don't even need to explicitly convert it to an array. F# will let you do splicing on a string. So a much better solution is:
let stringPeeler (s: string) = s.[1..(s.Length - 2)]
In F#. Not the most straightforward way to solve this, but I wanted to use the language Array splicing.
And it turns out that you don't even need to explicitly convert it to an array. F# will let you do splicing on a string. So a much better solution is: