看看这句话:
messageBox.show( System.Security.Principal.WindowsIdentity.GetCurrent().Name);
Run Code Online (Sandbox Code Playgroud)
该声明的输出是:
罗山\ mohdibrahim.tasal
但我只想展示给我:
mohdibrhaim.tasal
我怎样才能做到这一点?
您可以在"\"上拆分名称并检索第二项.
例如
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\')[1]
Run Code Online (Sandbox Code Playgroud)
编辑: 您首先要检查是否存在反斜杠,以确保安全 - 如果没有反斜杠,您只需要按原样使用名称.