-4

How can I get a part of a system's name? For instance if the computer name contains SERVER then do something, and if it includes CLIENT then do something else.

The names I an working with are similar to SERVER000455. The numerical values change all the time but the SERVER part is the same.

Getting the name is easy (SystemInformation.ComputerName), but that wasn't my question. My question was getting just the first part of the name. The string[] and split doesn't seem to work since it's not an array. I just need to get the prefix of the PC name and drop the numerical bit.

4

2 回答 2

3

好的,我认为主要问题是计算机名称。但你想要:

String machinename = System.Environment.MachineName;

if(machinename.ToUpper().Contains("SERVER"))
{

}
else if (machinename.ToUpper().Contains("CLIENT"))
{

}
于 2013-06-11T20:39:53.460 回答
2
if (Environment.MachineName.ToUpper().Contains("SERVER"))
{
    // etc.
}
于 2013-06-11T20:40:18.323 回答