Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fuss:libopenmetaverse [2015/01/05 23:46] – [Extract Full Avatar Name] officefuss:libopenmetaverse [2022/04/19 08:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== 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:
 +<code csharp>
 +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();
 +</code>
 +
 +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.1420501591.txt.bz2 · Last modified: 2015/01/05 23:46 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


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