Created
July 19, 2012 07:17
-
-
Save jinweijie/3141287 to your computer and use it in GitHub Desktop.
GetDomainUserName
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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