zoukankan      html  css  js  c++  java
  • foreach —(遍历数组或循环中的字符,以获取信息)

    namespace ConsoleApplication2
    {
    class Program
    {//letter 字母 gigit 数字 symbol 符号
    static void Main(string[] args)
    {
    Console.WriteLine("请输入字符");
    string s = Console.ReadLine();//输入的字符串用S来接收
    int letter = 0;//最开始字母的个数为0
    int gigit = 0; //最开始数字的个数为0
    int symbol = 0;//最开始字符的个数为0
    foreach (char c in s)
    { //foreach 语句用于循环访问集合以获取所需信息,语法 foreach(元素类型 c int 遍历对象s)
    if (char.IsLetter(c)) letter++;//提取字符串中的字母
    else if (char.IsDigit(c)) gigit++;//提取字符串中的数字
    else symbol++;//提取字符串中的符号
    }
    Console.WriteLine("字母的个数:" + letter + " " + "数字的个数:" + gigit + " " + "字符的个数:" + symbol);//输出
    Console.ReadLine();
    }
    }
    }

  • 相关阅读:
    express4.x socket
    validator
    服务管理,Dll查看
    复制程序,获取系统信息
    TCP HelloWord
    UDP HelloWord
    [置顶] 一个小马
    注册表编辑
    服务的启动与停止
    自下载运行
  • 原文地址:https://www.cnblogs.com/mywangpingan/p/7008821.html
Copyright © 2011-2022 走看看