Extract Full Avatar Name

libopenmetaverse uses different possible avatar name formats when passing avatar names. For example, an avatar name can be in one of the following formats:

  • FirstName LastName
  • FirstName.LastName
  • FirstName - in which case, the last name is Resident

The following brief LINQ query will help you resolve all these names to a list of two elements:

string avatarName = "Snooky Smexy";
// ...
List<string> name =
    new List<string>(Regex.Matches(avatarName, @"^(?<first>.*?)([\s\.]|$)(?<last>.*?)$")
        .Cast<Match>()
        .ToDictionary(o => new[]
        {
            o.Groups["first"].Value,
            o.Groups["last"].Value
        }).SelectMany(o => new[] {o.Key[0], !string.IsNullOrEmpty(o.Key[1]) ? o.Key[1] : "Resident"}));
Console.WriteLine(name.First());
Console.WriteLine(name.Last());
Console.ReadKey();

where the list name will have the first element set to the first name of the avatar and the last name set to the last name of the avatar (or Resident) if no last name was found.


fuss/libopenmetaverse.txt ยท Last modified: 2017/02/22 18:30 (external edit)

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.