You need to get the values into a collection object and then iterate through them and test it it is a group, if not assume it is a user, as follows:
SPFieldUserValueCollection objUserFieldValueCol = new SPFieldUserValueCollection(web, listitem["UserGroupField"].ToString());
for (int i = 0; i < objUserFieldValueCol.Count; i++)
{
SPFieldUserValue singlevalue = objUserFieldValueCol[i];
if (singlevalue.User == null) // value is a SharePoint group if User is null
{
SPGroup group = web.Groups[singlevalue.LookupValue];
foreach (SPUser user in group.Users)
{
//do stuff with the user
}
}
else // singlevalue.User value is a user
{
//do stuff for the singlevalue.User
}
}
I am assuming that you will not have any AD security groups in there, otherwise you will need add some code to handle those.