我有以" domain \ alias"格式存储的字符串。我只需要在第二个字符串中存储域名。这样做的最短路径是什么?没有任何循环?
答案 0 :(得分:2)
public string GetUserNameFromServicePrinciple(string principleName)
{
string userName = principleName; //if input is just username and not a valid service principle name with domain
if (!string.IsNullOrEmpty(principleName))
{
var splittedParts = principleName.Split(@"\".ToCharArray());
userName = splittedParts.Length > 1 ? splittedParts[1] : principleName;
}
return userName;
}