输入必须为大写(首字母)和小写(其他) [英] Input must be upper case(first letter) and lower case (others)

查看:79
本文介绍了输入必须为大写(首字母)和小写(其他)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来创建一个程序,该程序要求在 UPPER 情况下输入首字母,在 lower 情况下输入所有其他字母.

I need some help creating a program that requires input with first letter in UPPER case and all other in lower case.

我认为你们中有些人不了解这个问题.我必须创建一个循环,要求用户从上至下输入第一个数字,如果不满足要求,则用户必须再次输入,直到第一个字母在上而其他字母在下.

I think some of u didnt understand the problem. I have to create a loop that requires from the user to enter the first number in upper and others in lower, if the requirements are not met, the user must input once again, until the first letter is upper and others are lower.

var novaDrzava = new Država ();
Console.Write ("Vnesite ime (prva začetnica naj bo velika, ostale male): ");

novaDrzava.Ime = Console.ReadLine ();

var drzava = novaDrzava.Ime;
var inicialka = drzava.Substring (0);
var ostale = drzava.Substring (1, drzava.Length - 1);

for (int i = 0; i <= malecrke.Length; i++) {
    if (inicialka.Contains (velikecrke[i])) {
        if (ostale.Contains (malecrke[i])) {
            break;
        } else {
            Console.WriteLine ("Ponovno vnesite ime");
            novaDrzava.Ime = Console.ReadLine ();
        }
    }
}

推荐答案

static void Main(string[] args)
        {
            string inputValue = Console.ReadLine();

            bool isValid = true;
            foreach (char val in inputValue)
            {
                if (inputValue.First()==val && char.IsUpper(val))
                {
                  //do nothing.
                }
                else if(char.IsLower(val))
                {
                    // do nothing.
                }
                else
                {
                    isValid = false;
                    Console.WriteLine("Invalid input string");
                    Console.ReadLine();
                    break;
                }
            }

            if (isValid)
            {
                Console.WriteLine("Valid input string");
                Console.ReadLine();
            }

        }

这篇关于输入必须为大写(首字母)和小写(其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆