Message Boards Message Boards


How Can I Convert Entities to Strings?

Posted 8 years ago
4 Replies
4 Total Likes

Hi everyone, I'm working with a long list of country names, which are strings. I want to make sure that my form of the names is the same as that used by Wolfram so that I can use CountryData. The trouble is, I can't do a comparison because


gives me a list of names but their Heads are Entity rather than String. Pain in the neck. How can I convert this list to strings so that I can edit my list of names? Any advice would be much appreciated.


POSTED BY: Gregory Lypny
4 Replies

Good stuff, Sean. Thank you for the tip. I obviously need to do my homework on this.


POSTED BY: Gregory Lypny

Standardly "Name" is the property of many entities which gives you the string:

Cases[EntityProperties["Country"], "Name", Infinity]


So when this is the case then this works:

c = CountryData["Countries"];
EntityValue[c, "Name"]

But generally speaking Entity is just a function:

Entity["Country", "Afghanistan"]

so this always works:

c[[All, 2]]
POSTED BY: Vitaliy Kaurov

Hi Vitaliy,

Sorry for my late reply. Thank you for your tip. Works like a charm. I'll have to do some homework on Entities and Objects to learn how I can make the most use of them.


POSTED BY: Gregory Lypny
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract