I have string that I want to chop to array of substrings of given length n. I am not interested in remainder (if length of string cannot be divided by n without remainder)
let ChopString (myString : string) n = let res = seq{ for i = 0 to myString.Length / n - 1 do yield( String.sub myString (i*n) n ) } |> Seq.to_array res
This is the best I could do. It looks ugly to me.
Is there nicer/shorter version of this, maybe without for loop?
stringInstance.[start..end]is much more readable thanString.sub. Here’s what I came up with:Or you can use: