你的位置:首页 > 软件开发 > ASP.net > C#——字符操作

C#——字符操作

发布时间:2016-09-17 16:00:12
题目要求:用户随机输入字母及数字组成的字符串,当用户连续输入字符串‘hello’时,程序结束用户输入,并分别显示用户输入的字母及数字的数目。代码:using System;using System.Collections.Generic;u ...

题目要求:用户随机输入字母及数字组成的字符串,当用户连续输入字符串‘hello’时,程序结束用户输入,并分别显示用户输入的字母及数字的数目。

代码:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 字符操作{  public class Program  {    public static void Main()    {      char s = '#';      int LetterIndex = 0, DigitIndex = 0;      Console.Write("请输入一个字符串(当输入hello时结束):");    turn:if(s!='h')      {        if (char.IsLetter(s))        LetterIndex++;      if (char.IsDigit(s))        DigitIndex++;      s = Console.ReadKey().KeyChar;      }      if (s == 'h')      {        LetterIndex++;        s = Console.ReadKey().KeyChar;        if (s == 'e')        {          LetterIndex++;          s = Console.ReadKey().KeyChar;          if (s == 'l')          {            LetterIndex++;             s = Console.ReadKey().KeyChar;            if (s == 'l')            {              LetterIndex++;              s = Console.ReadKey().KeyChar;              if (s == 'o')              {                LetterIndex++;                Console.WriteLine("\n共有字母{0}个,数字{1}个.", LetterIndex, DigitIndex);                Console.WriteLine("按任意键结束.");                Console.ReadKey();              }              else                goto turn;            }            else              goto turn;          }          else            goto turn;        }        else          goto turn;      }      else        goto turn;    }  }}

原标题:C#——字符操作

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录