I'm storing heights in my database as 62 or 511 instead of 6 ft 2 or 5 ft 11.
This is how I prepare the string that will be saved:
let height = 6 ft 2
let myNewString = height.stringByReplacingOccurrencesOfString(" ft ", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
println(myNewString) // 62
What I'd like to do is now do the opposite thing when displaying back the data from the database.
So I'd like to take the returned "62" from the database and insert this string " ft " into it. My aim is to end up with "6 ft 2" to display on the app.
How can I do this?
I want to avoid storing two columns dedicated to height in my database. I only know how to concatenate strings but this isn't exactly concatenating a string. I am inserting it into an existing string.
I'd appreciate an efficient way to do this. Been looking around for a while now and can't seem to find my solution.
Thanks for your time.
Update:
After reading comments I'm wondering if it would be better to add a decimal point after the first char in string e.g. 4.2, 4.10, 5.4, 5.11, 6.2 etc
let height = 6 ft 2
let myNewString = height.stringByReplacingOccurrencesOfString(" ft ", withString: ".", options: NSStringCompareOptions.LiteralSearch, range: nil)
println(myNewString) // 6.2
111could be11 ft 1or1 ft 11.