Mark Locklear
Mark Locklear

Reputation: 5355

Create unique integer from an alpha-numeric string

I am seeding a database in Rails. The seed data contain ID's, and I need to set those ID's as my primary keys. The primary keys in the seeded data are alpha-numeric. Rails needs its primary keys to be integers. I am thinking there has to be some way to convert an alpha-numeric string to a unique integer. It can't be random. Something equivalent to the decoder ring in your cracker jacks.

Upvotes: 1

Views: 1983

Answers (1)

sawa
sawa

Reputation: 168239

If you do not need to distinguish upper and lower cases, then for example,

"fkfj23".to_i(36) # => 941309499

Upvotes: 6

Related Questions