打印出“IP地址为***的服务器的***端口提供的服务为***” (字符串操作)

"192.168.10.5[port=21,type =ftp]",这个字符串表示IP地址为192.168.10.5的服务器的21端口提供的是ftp服务器,
            //其中如果“,type=ftp”部分被省略,则默认为http服务器,请用程序解析此字符串,然后打印出“IP地址为***的服务器的***端口提供的服务为***”,line.Contains("type=").192,168.10.5[port = 21]

namespace _06字符串练习
{
    class Program
    {
        static void Main(string[] args)
        {
            #region :"192.168.10.5[port=21,type =ftp]",这个字符串表示IP地址为192.168.10.5的服务器的21端口提供的是ftp服务器,
            //其中如果“,type=ftp”部分被省略,则默认为http服务器,请用程序解析此字符串,然后打印出“IP地址为***的服务器的***端口提供的服务为***”,line.Contains("type=").192,168.10.5[port = 21]
            string str = "192.168.10.5[port=21,type =ftp]";
           string[] lines= str.Split(new string[] { "[port=", ",type =", "]" }, StringSplitOptions.RemoveEmptyEntries);//按照字符串切割
            Console.WriteLine("ip为:{0}",lines[0]);
            Console.WriteLine("端口为:{0}", lines[1]);
            Console.WriteLine("服务器为:{0}",lines.Length> 2 ? lines[2] : "http");
            


            #endregion

        }
    }
}

猜你喜欢

转载自blog.csdn.net/nsjlive/article/details/81112763