-
-
Save iamjason/8f8f4bc00c13de86bcad to your computer and use it in GitHub Desktop.
let state = [ "AK - Alaska", | |
"AL - Alabama", | |
"AR - Arkansas", | |
"AS - American Samoa", | |
"AZ - Arizona", | |
"CA - California", | |
"CO - Colorado", | |
"CT - Connecticut", | |
"DC - District of Columbia", | |
"DE - Delaware", | |
"FL - Florida", | |
"GA - Georgia", | |
"GU - Guam", | |
"HI - Hawaii", | |
"IA - Iowa", | |
"ID - Idaho", | |
"IL - Illinois", | |
"IN - Indiana", | |
"KS - Kansas", | |
"KY - Kentucky", | |
"LA - Louisiana", | |
"MA - Massachusetts", | |
"MD - Maryland", | |
"ME - Maine", | |
"MI - Michigan", | |
"MN - Minnesota", | |
"MO - Missouri", | |
"MS - Mississippi", | |
"MT - Montana", | |
"NC - North Carolina", | |
"ND - North Dakota", | |
"NE - Nebraska", | |
"NH - New Hampshire", | |
"NJ - New Jersey", | |
"NM - New Mexico", | |
"NV - Nevada", | |
"NY - New York", | |
"OH - Ohio", | |
"OK - Oklahoma", | |
"OR - Oregon", | |
"PA - Pennsylvania", | |
"PR - Puerto Rico", | |
"RI - Rhode Island", | |
"SC - South Carolina", | |
"SD - South Dakota", | |
"TN - Tennessee", | |
"TX - Texas", | |
"UT - Utah", | |
"VA - Virginia", | |
"VI - Virgin Islands", | |
"VT - Vermont", | |
"WA - Washington", | |
"WI - Wisconsin", | |
"WV - West Virginia", | |
"WY - Wyoming"] |
one big array for those who don't want indentation
states = ["Alaska", "Alabama", "Arkansas", "American Samoa", "Arizona", "California", "Colorado", "Connecticut", "District of Columbia", "Delaware", "Florida", "Georgia", "Guam", "Hawaii", "Iowa", "Idaho", "Illinois", "Indiana", "Kansas", "Kentucky", "Louisiana", "Massachusetts", "Maryland", "Maine", "Michigan", "Minnesota", "Missouri", "Mississippi", "Montana", "North Carolina", "North Dakota", "Nebraska", "New Hampshire", "New Jersey", "New Mexico", "Nevada", "New York", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Virginia", "Virgin Islands", "Vermont", "Washington", "Wisconsin", "West Virginia", "Wyoming"]
Thanks, very helpful
Thank you very much guys! Really helpful! :D
Useful stuff. Thank you.
Thank you to all that shared, it is very helpful.
Thanks for the list......am i really that lazy :)
FYI, because the original post was sorted alphabetically by state code (which itself is likely not what you want), all further iterations of this list are out of order by state name.
let states = [ "AK","AL","AR","AS","AZ","CA","CO","CT","DC","DE","FL","GA","GU","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY"]
Here's another version I made if anyone wants to use it.
let stateDictionary: [String : String] = [ "Alaska" : "AK", "Alabama" : "AL", "Arkansas" : "AR", "American Samoa" : "AS", "Arizona" : "AZ", "California" : "CA", "Colorado" : "CO", "Connecticut" : "CT", "District of Columbia" : "DC", "Delaware" : "DE", "Florida" : "FL", "Georgia" : "GA", "Guam" : "GU", "Hawaii" : "HI", "Iowa" : "IA", "Idaho" : "ID", "Illinois" : "IL", "Indiana" : "IN", "Kansas" : "KS", "Kentucky" : "KY", "Louisiana" : "LA", "Massachusetts" : "MA", "Maryland" : "MD", "Maine" : "ME", "Michigan" : "MI", "Minnesota" : "MN", "Missouri" : "MO", "Mississippi" : "MS", "Montana" : "MT", "North Carolina" : "NC", "North Dakota" : "ND", "Nebraska" : "NE", "New Hampshire" : "NH", "New Jersey" : "NJ", "New Mexico" : "NM", "Nevada" : "NV", "New York" : "NY", "Ohio" : "OH", "Oklahoma" : "OK", "Oregon" : "OR", "Pennsylvania" : "PA", "Puerto Rico" : "PR", "Rhode Island" : "RI", "South Carolina" : "SC", "South Dakota" : "SD", "Tennessee" : "TN", "Texas" : "TX", "Utah" : "UT", "Virginia" : "VA", "Virgin Islands" : "VI", "Vermont" : "VT", "Washington" : "WA", "Wisconsin" : "WI", "West Virginia" : "WV", "Wyoming" : "WY"]
thanks a lot!
Here's a Swift extension
to convert two character state abbreviations to the long-form state name. If there's no valid state, it returns the inputted string:
extension String {
func longStateName() -> String {
// check that it's a valid length
guard self.characters.count == 2 else { return self }
// declare dictionary
let stateDictionary: [String : String] = [
"AK" : "Alaska",
"AL" : "Alabama",
"AR" : "Arkansas",
"AS" : "American Samoa",
"AZ" : "Arizona",
"CA" : "California",
"CO" : "Colorado",
"CT" : "Connecticut",
"DC" : "District of Columbia",
"DE" : "Delaware",
"FL" : "Florida",
"GA" : "Georgia",
"GU" : "Guam",
"HI" : "Hawaii",
"IA" : "Iowa",
"ID" : "Idaho",
"IL" : "Illinois",
"IN" : "Indiana",
"KS" : "Kansas",
"KY" : "Kentucky",
"LA" : "Louisiana",
"MA" : "Massachusetts",
"MD" : "Maryland",
"ME" : "Maine",
"MI" : "Michigan",
"MN" : "Minnesota",
"MO" : "Missouri",
"MS" : "Mississippi",
"MT" : "Montana",
"NC" : "North Carolina",
"ND" : " North Dakota",
"NE" : "Nebraska",
"NH" : "New Hampshire",
"NJ" : "New Jersey",
"NM" : "New Mexico",
"NV" : "Nevada",
"NY" : "New York",
"OH" : "Ohio",
"OK" : "Oklahoma",
"OR" : "Oregon",
"PA" : "Pennsylvania",
"PR" : "Puerto Rico",
"RI" : "Rhode Island",
"SC" : "South Carolina",
"SD" : "South Dakota",
"TN" : "Tennessee",
"TX" : "Texas",
"UT" : "Utah",
"VA" : "Virginia",
"VI" : "Virgin Islands",
"VT" : "Vermont",
"WA" : "Washington",
"WI" : "Wisconsin",
"WV" : "West Virginia",
"WY" : "Wyoming"]
// check that key is in the dictionary
guard stateDictionary[self.uppercased()] != nil else { return self }
// if it's in the dictionary, return the longStateName
if let longStateName = stateDictionary[self.uppercased()] {
return longStateName
}
// If, after all that, there's nothing there, return the string that was fed to the method
return self
}
}
Usage
// returns "Alaska"
"ak".longStateName()
Made this using CapnCaleb's list for a Bootstrap Vue select box
let stateList = [
{ value: "AK", text: "Alaska" },
{ value: "AL", text: "Alabama" },
{ value: "AR", text: "Arkansas" },
{ value: "AS", text: "American Samoa" },
{ value: "AZ", text: "Arizona" },
{ value: "CA", text: "California" },
{ value: "CO", text: "Colorado" },
{ value: "CT", text: "Connecticut" },
{ value: "DC", text: "District of Columbia" },
{ value: "DE", text: "Delaware" },
{ value: "FL", text: "Florida" },
{ value: "GA", text: "Georgia" },
{ value: "GU", text: "Guam" },
{ value: "HI", text: "Hawaii" },
{ value: "IA", text: "Iowa" },
{ value: "ID", text: "Idaho" },
{ value: "IL", text: "Illinois" },
{ value: "IN", text: "Indiana" },
{ value: "KS", text: "Kansas" },
{ value: "KY", text: "Kentucky" },
{ value: "LA", text: "Louisiana" },
{ value: "MA", text: "Massachusetts" },
{ value: "MD", text: "Maryland" },
{ value: "ME", text: "Maine" },
{ value: "MI", text: "Michigan" },
{ value: "MN", text: "Minnesota" },
{ value: "MO", text: "Missouri" },
{ value: "MS", text: "Mississippi" },
{ value: "MT", text: "Montana" },
{ value: "NC", text: "North Carolina" },
{ value: "ND", text: "North Dakota" },
{ value: "NE", text: "Nebraska" },
{ value: "NH", text: "New Hampshire" },
{ value: "NJ", text: "New Jersey" },
{ value: "NM", text: "New Mexico" },
{ value: "NV", text: "Nevada" },
{ value: "NY", text: "New York" },
{ value: "OH", text: "Ohio" },
{ value: "OK", text: "Oklahoma" },
{ value: "OR", text: "Oregon" },
{ value: "PA", text: "Pennsylvania" },
{ value: "PR", text: "Puerto Rico" },
{ value: "RI", text: "Rhode Island" },
{ value: "SC", text: "South Carolina" },
{ value: "SD", text: "South Dakota" },
{ value: "TN", text: "Tennessee" },
{ value: "TX", text: "Texas" },
{ value: "UT", text: "Utah" },
{ value: "VA", text: "Virginia" },
{ value: "VI", text: "Virgin Islands" },
{ value: "VT", text: "Vermont" },
{ value: "WA", text: "Washington" },
{ value: "WI", text: "Wisconsin" },
{ value: "WV", text: "West Virginia" },
{ value: "WY", text: "Wyoming" }
]
thanks a lot, useful
PHP Array
'US' => [ 'AK' => 'Alaska', 'AL' => 'Alabama', 'AR' => 'Arkansas', 'AS' => 'American Samoa', 'AZ' => 'Arizona', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DC' => 'District of Columbia', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'GU' => 'Guam', 'HI' => 'Hawaii', 'IA' => 'Iowa', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'MA' => 'Massachusetts', 'MD' => 'Maryland', 'ME' => 'Maine', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MO' => 'Missouri', 'MS' => 'Mississippi', 'MT' => 'Montana', 'NC' => 'North Carolina', 'ND' => ' North Dakota', 'NE' => 'Nebraska', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NV' => 'Nevada', 'NY' => 'New York', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'PR' => 'Puerto Rico', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VA' => 'Virginia', 'VI' => 'Virgin Islands', 'VT' => 'Vermont', 'WA' => 'Washington', 'WI' => 'Wisconsin', 'WV' => 'West Virginia', 'WY' => 'Wyoming' ]
just thanks again for the help
Thanks for this list!
Just a heads up for non Americans coming across this gist...
Guam, Puerto Rico, Virgin Islands (US), American Samoa are US Territories NOT US States
District of Columbia is a Federal District NOT a State.
The array count for US States should be 50.
Here's a list to find out how well your User Acceptance Testing Dept does their jobs:
let states = [
"AK - Alaska",
"AL - Alabama",
"AR - Arkansas",
"AS - American Samoa",
"AZ - Arizona",
"CA - California",
"CO - Colorado",
"CT - Connecticut",
"DC - District of Columbia",
"DE - Delaware",
"FL - Florida",
"FP - Fictional Place",
"GA - Georgia",
"GU - Guam",
"HI - Hawaii",
"IA - Iowa",
"ID - Idaho",
"IL - Illinois",
"IN - Indiana",
"KS - Kansas",
"KY - Kentucky",
"LA - Louisiana",
"LG - Laguardia",
"MA - Massachusetts",
"MD - Maryland",
"ME - Maine",
"MI - Michigan",
"MN - Minnesota",
"MO - Missouri",
"MS - Mississippi",
"MT - Montana",
"NC - North Carolina",
"ND - North Dakota",
"NE - Nebraska",
"NH - New Hampshire",
"NJ - New Jersey",
"NM - New Mexico",
"NT - North Tomato",
"NV - Nevada",
"NY - New York",
"OH - Ohio",
"OK - Oklahoma",
"OR - Oregon",
"PA - Pennsylvania",
"PR - Puerto Rico",
"RI - Rhode Island",
"SC - South Carolina",
"SD - South Dakota",
"TN - Tennessee",
"TX - Texas",
"UT - Utah",
"VA - Virginia",
"VI - Virgin Islands",
"VT - Vermont",
"WA - Washington",
"WI - Wisconsin",
"WV - West Virginia",
"WWW - World Wide Web",
"WY - Wyoming"
]
As a Swift Enum
enum State: String, CaseIterable {
case alaska = "AK"
case alabama = "AL"
case arkansas = "AR"
case americanSamoa = "AS"
case arizona = "AZ"
case california = "CA"
case colorado = "CO"
case connecticut = "CT"
case districtOfColumbia = "DC"
case delaware = "DE"
case florida = "FL"
case georgia = "GA"
case guam = "GU"
case hawaii = "HI"
case iowa = "IA"
case idaho = "ID"
case illinois = "IL"
case indiana = "IN"
case kansas = "KS"
case kentucky = "KY"
case louisiana = "LA"
case massachusetts = "MA"
case maryland = "MD"
case maine = "ME"
case michigan = "MI"
case minnesota = "MN"
case missouri = "MO"
case mississippi = "MS"
case montana = "MT"
case northCarolina = "NC"
case northDakota = "ND"
case nebraska = "NE"
case newHampshire = "NH"
case newJersey = "NJ"
case newMexico = "NM"
case nevada = "NV"
case newYork = "NY"
case ohio = "OH"
case oklahoma = "OK"
case oregon = "OR"
case pennsylvania = "PA"
case ruertoRico = "PR"
case rhodeIsland = "RI"
case southCarolina = "SC"
case southDakota = "SD"
case tennessee = "TN"
case texas = "TX"
case utah = "UT"
case virginia = "VA"
case virginIslands = "VI"
case vermont = "VT"
case washington = "WA"
case wisconsin = "WI"
case westVirginia = "WV"
case wyoming = "WY"
}
The United States has 50 states, this list is so wrong.
If anyone wants a list that is actually ORDERED -
@objc static let states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]
I love all of this.
Here's the dictionary with the abbreviations as the values and full names as keys.
let stateDictionary = [
"Alaska" : "AK",
"Alabama" : "AL",
"Arkansas" : "AR",
"American Samoa" : "AS",
"Arizona" : "AZ",
"California" : "CA",
"Colorado" : "CO",
"Connecticut" : "CT",
"District of Columbia" : "DC",
"Delaware" : "DE",
"Florida" : "FL",
"Georgia" : "GA",
"Guam" : "GU",
"Hawaii" : "HI",
"Iowa" : "IA",
"Idaho" : "ID",
"Illinois" : "IL",
"Indiana" : "IN",
"Kansas" : "KS",
"Kentucky" : "KY",
"Louisiana" : "LA",
"Massachusetts" : "MA",
"Maryland" : "MD",
"Maine" : "ME",
"Michigan" : "MI",
"Minnesota" : "MN",
"Missouri" : "MO",
"Mississippi" : "MS",
"Montana" : "MT",
"North Carolina" : "NC",
"North Dakota" : "ND",
"Nebraska" : "NE",
"New Hampshire" : "NH",
"New Jersey" : "NJ",
"New Mexico" : "NM",
"Nevada" : "NV",
"New York" : "NY",
"Ohio" : "OH",
"Oklahoma" : "OK",
"Oregon" : "OR",
"Pennsylvania" : "PA",
"Puerto Rico" : "PR",
"Rhode Island" : "RI",
"South Carolina" : "SC",
"South Dakota" : "SD",
"Tennessee" : "TN",
"Texas" : "TX",
"Utah" : "UT",
"Virginia" : "VA",
"Virgin Islands" : "VI",
"Vermont" : "VT",
"Washington" : "WA",
"Wisconsin" : "WI",
"West Virginia" : "WV",
"Wyoming" : "WY"
]
Thanks for this! Y'all are awesome
Here is a dictionary for the state abbreviations and a Bool value:
let states: [String: Bool] = [ "AK": false, "AL": false, "AR": false, "AS": false, "AZ": false, "CA": false, "CO": false, "CT": false, "DC": false, "DE": false, "FL": false, "GA": false, "GU": false, "HI": false, "IA": false, "ID": false, "IL": false, "IN": false, "KS": false, "KY": false, "LA": false, "MA": false, "MD": false, "ME": false, "MI": false, "MN": false, "MO": false, "MS": false, "MT": false, "NC": false, "ND": false, "NE": false, "NH": false, "NJ": false, "NM": false, "NV": false, "NY": false, "OH": false, "OK": false, "OR": false, "PA": false, "PR": false, "RI": false, "SC": false, "SD": false, "TN": false, "TX": false, "UT": false, "VA": false, "VI": false, "VT": false, "WA": false, "WI": false, "WV": false, "WY": false]
Here's a Swift enum, alphabetically sorted by their display name, that includes the 50 states + DC only (so it doesn't include insular areas such as American Samoa, Guam, Puerto Rico, the US Virgin Islands, etc).
Also, it was reviewed for copy, typos and other common mistakes (if you pay attention to the code snippets posted throughout this gist, there're tons of typos 😂 )
Enjoy:
enum AmericanState : String, CaseIterable {
case alabama = "AL"
case alaska = "AK"
case arizona = "AZ"
case arkansas = "AR"
case california = "CA"
case colorado = "CO"
case connecticut = "CT"
case delaware = "DE"
case districtOfColumbia = "DC"
case florida = "FL"
case georgia = "GA"
case hawaii = "HI"
case idaho = "ID"
case illinois = "IL"
case indiana = "IN"
case iowa = "IA"
case kansas = "KS"
case kentucky = "KY"
case louisiana = "LA"
case maine = "ME"
case maryland = "MD"
case massachusetts = "MA"
case michigan = "MI"
case minnesota = "MN"
case mississippi = "MS"
case missouri = "MO"
case montana = "MT"
case nebraska = "NE"
case nevada = "NV"
case newHampshire = "NH"
case newJersey = "NJ"
case newMexico = "NM"
case newYork = "NY"
case northCarolina = "NC"
case northDakota = "ND"
case ohio = "OH"
case oklahoma = "OK"
case oregon = "OR"
case pennsylvania = "PA"
case rhodeIsland = "RI"
case southCarolina = "SC"
case southDakota = "SD"
case tennessee = "TN"
case texas = "TX"
case utah = "UT"
case vermont = "VT"
case virginia = "VA"
case washington = "WA"
case westVirginia = "WV"
case wisconsin = "WI"
case wyoming = "WY"
var displayName: String {
switch self {
case .alabama: return NSLocalizedString("Alabama", comment: "")
case .alaska: return NSLocalizedString("Alaska", comment: "")
case .arizona: return NSLocalizedString("Arizona", comment: "")
case .arkansas: return NSLocalizedString("Arkansas", comment: "")
case .california: return NSLocalizedString("California", comment: "")
case .colorado: return NSLocalizedString("Colorado", comment: "")
case .connecticut: return NSLocalizedString("Connecticut", comment: "")
case .delaware: return NSLocalizedString("Delaware", comment: "")
case .districtOfColumbia: return NSLocalizedString("District of Columbia", comment: "")
case .florida: return NSLocalizedString("Florida", comment: "")
case .georgia: return NSLocalizedString("Georgia", comment: "")
case .hawaii: return NSLocalizedString("Hawaii", comment: "")
case .idaho: return NSLocalizedString("Idaho", comment: "")
case .illinois: return NSLocalizedString("Illinois", comment: "")
case .indiana: return NSLocalizedString("Indiana", comment: "")
case .iowa: return NSLocalizedString("Iowa", comment: "")
case .kansas: return NSLocalizedString("Kansas", comment: "")
case .kentucky: return NSLocalizedString("Kentucky", comment: "")
case .louisiana: return NSLocalizedString("Louisiana", comment: "")
case .maine: return NSLocalizedString("Maine", comment: "")
case .maryland: return NSLocalizedString("Maryland", comment: "")
case .massachusetts: return NSLocalizedString("Massachusetts", comment: "")
case .michigan: return NSLocalizedString("Michigan", comment: "")
case .minnesota: return NSLocalizedString("Minnesota", comment: "")
case .mississippi: return NSLocalizedString("Mississippi", comment: "")
case .missouri: return NSLocalizedString("Missouri", comment: "")
case .montana: return NSLocalizedString("Montana", comment: "")
case .nebraska: return NSLocalizedString("Nebraska", comment: "")
case .nevada: return NSLocalizedString("Nevada", comment: "")
case .newHampshire: return NSLocalizedString("New Hampshire", comment: "")
case .newJersey: return NSLocalizedString("New Jersey", comment: "")
case .newMexico: return NSLocalizedString("New Mexico", comment: "")
case .newYork: return NSLocalizedString("New York", comment: "")
case .northCarolina: return NSLocalizedString("North Carolina", comment: "")
case .northDakota: return NSLocalizedString("North Dakota", comment: "")
case .ohio: return NSLocalizedString("Ohio", comment: "")
case .oklahoma: return NSLocalizedString("Oklahoma", comment: "")
case .oregon: return NSLocalizedString("Oregon", comment: "")
case .pennsylvania: return NSLocalizedString("Pennsylvania", comment: "")
case .rhodeIsland: return NSLocalizedString("Rhode Island", comment: "")
case .southCarolina: return NSLocalizedString("South Carolina", comment: "")
case .southDakota: return NSLocalizedString("South Dakota", comment: "")
case .tennessee: return NSLocalizedString("Tennessee", comment: "")
case .texas: return NSLocalizedString("Texas", comment: "")
case .utah: return NSLocalizedString("Utah", comment: "")
case .vermont: return NSLocalizedString("Vermont", comment: "")
case .virginia: return NSLocalizedString("Virginia", comment: "")
case .washington: return NSLocalizedString("Washington", comment: "")
case .westVirginia: return NSLocalizedString("West Virginia", comment: "")
case .wisconsin: return NSLocalizedString("Wisconsin", comment: "")
case .wyoming: return NSLocalizedString("Wyoming", comment: "")
}
}
}
You can copy different formats of states data from here: https://usastatescode.com/state-array-json
Thank you very much.
statesPopUpButton.removeAllItems()
statesPopUpButton.addItems(withTitles: states)
Thanks, It's very helpful to me