Skip to content

Instantly share code, notes, and snippets.

@jinweijie
Created July 19, 2012 07:17
Show Gist options
  • Save jinweijie/3141287 to your computer and use it in GitHub Desktop.
Save jinweijie/3141287 to your computer and use it in GitHub Desktop.
GetDomainUserName
using System;
using System.IO;
/// <summary>
/// GetDomainUserName
/// </summary>
public class GetDomainUserName
{
/// <summary>
/// The main entry point for the application
/// </summary>
[STAThread]
public static void Main( string[] args )
{
Console.WriteLine( GetUserName("") );
Console.WriteLine( GetUserName("MyDomain\\weijie") );
Console.WriteLine( GetUserName("weijie") );
}
public static string GetUserName(string raw){
if( string.IsNullOrEmpty(raw) )
return string.Empty;
string[] tokens = raw.Split('\\');
if( tokens.Length == 1 )
return tokens[0];
return tokens[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment