Message Boards Message Boards

1
|
7581 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How Can I Convert Entities to Strings?

Posted 10 years ago

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

CountryData["Countries"]

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.

Gregory

POSTED BY: Gregory Lypny
4 Replies

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

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

{"Name"}

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
Posted 10 years ago

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.

Gregory

POSTED BY: Gregory Lypny
Posted 10 years ago

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

Gregory

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

Group Abstract Group Abstract