Rob Lyndon
Rob Lyndon

Reputation: 12651

Range Operator for Base62 Encoding

For base 62 encoding, I need all 62 alphanumeric characters. The F# range operator offers a nice shorthand for this.

let alphaNumericCharacters =
    seq {
        yield! [|'a'..'z'|]
        yield! [|'A'..'Z'|]
        yield! [|'0'..'9'|]
    } |> Array.ofSeq

This is nice and concise, but I'm greedy. Is there a way of doing this in one line?

Upvotes: 3

Views: 89

Answers (3)

Good Night Nerd Pride
Good Night Nerd Pride

Reputation: 8452

If your feeling funny:

let alphaNumericCharacters = [|Char.MinValue..Char.MaxValue|] |> Array.filter Char.IsLetterOrDigit

Upvotes: 0

Jonathan Wilson
Jonathan Wilson

Reputation: 4295

let alphaNumericCharacters = ['a'..'z'] @ ['A'..'Z'] @ ['0'..'9'] |> List.toArray

Upvotes: 1

ildjarn
ildjarn

Reputation: 62975

let alphaNumericCharacters = Array.concat [| [|'0'..'9'|]; [|'A'..'Z'|]; [|'a'..'z'|] |]

Upvotes: 2

Related Questions