if you look at the api doc (for csv)
IP Geolocation API - CSV [ip-api][
^] you'll see that the return info is
success,COUNTRY,COUNTRY CODE,REGION CODE,REGION NAME,CITY,ZIP CODE,LATITUDE,LONGITUDE,TIME ZONE,ISP NAME,ORGANIZATION NAME,AS NUMBER / NAME,IP ADDRESS USED FOR QUERY
so, if you do a string.Split ie
char[] delimiterChars = { ',' };
String[] csvElements = reply.Split(delimiterChars);
string ipCountry = csvElements[1];
or
string ipCountry = csvElements[2];
IF csvElements[0] == "success" that is
You can wrap the whole thing into a function, pass in int 1 or 2 for 'which' country version you want back, returned as a string, or perhaps string.Empty if not 'success'
[edit] something like this (not compiled or tested)
static string getCountryFromReply(string reply, int countryVersion)
{
if (!(reply.Trim().StartsWith("success")))
{
return string.Empty;
}
if (countryVersion != 1 && countryVersion != 2)
{
throw new argumentException("Only 1 or 2 Valid", "countryVersion");
}
char[] delimiterChars = {‘,’};
string[] csvElements = reply.Split(delimiterChars);
return csvElements(countryVersion);
}
[/edit]
is what I had in mind - you'll need to retype it though and check it carefully, the "" are from my Mac, VS will likely swear at you, but thats the gist - you could also make countryVersion an enum to make it easier to remember,
enum countryVersionReturn {countryLong=1, countryShort};
if you dont like any of this, then, you can also look at just requesting the fields you want
IP Geolocation API - Return values [ip-api][
^] in your case country,countryCode, Im not sure if that returns the status ie success / fail, I would always include the status field anyway, which means you still have to split the string