A..." />

F# split array of strings and return the result of split?

You should check whether each string can split into two pieces, and unzip the result: let total = | "1X2"; "3X4"; "5X6" | let odds, evens = total |> Array. Map (fun x -> match x. Split('X') with | |odd; even| -> odd, even | _ -> failwith "Wrong input") |> Array.unzip.

Thank you very much for your great code! Besides, it is very good that your code did a careful condition check, otherwise, there could be some wrong input to ruin the results! Thanks and have a nice weekend!

– John John Oct 30 at 7:31 Assuming this is numeric odd and even - above solution will not work correctly for let total = | "2X1"; "3X4"; "6X8" | – swapneel Oct 31 at 9:34 1 I assume the solution is for odd and even positions in each split string array. – pad Oct 31 at 10:26.

Let evens, odds = total |> (Array. Map (fun x -> x. Split('X'))) |> Array.

Concat |> Array. Partition (fun s -> int s % 2 = 0) EDIT: As John Palmer points out in the comments, you can use Array. Collect instead of map and concat: let evens, odds = total |> Array.

Collect (fun s -> s. Split('X')) |> Array. Partition (fun s -> int s % 2 = 0).

I m having below error – swapneel Oct 29 at 23:16 |> (Array. Map (fun x -> x. Split('X'))) ----^^ stdin(26,5): error FS0010: Unexpected infix operator in binding.

Expected incomplete structured construct at or before this point or other token. – swapneel Oct 29 at 23:16 @swapneel - I think it's an indentation problem - try indenting the lines after the first so they level with 'total' in the first. – Lee Oct 29 at 23:25 @Lee - You can youse Array.

Collect rather than Array. Map ... |> Array. Concat – John Palmer Oct 30 at 11:22 @JohnPalmer - Thanks, I wasn't aware of collect.

– Lee Oct 30 at 11:46.

Let odd = oddEven |> Array. Map (fun x -> x.0) let even = oddEven |> Array. Map (fun x -> x.1).

OddEven is ||"1"; "2"|; |"3"; "4"|; |"5"; "6"|| – BLUEPIXY Oct 30 at 11:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions