软件编程
位置:首页>> 软件编程>> C#编程>> C#找出字符串中第一个字母并大写的方法

C#找出字符串中第一个字母并大写的方法

作者:礼拜一  发布时间:2023-08-24 03:43:28 

标签:C#,字符串

本文实例讲述了C#找出字符串中第一个字母并大写的方法。分享给大家供大家参考,具体如下:


class Program
{
 static void Main(string[] args)
 {
  String aa = "%.,46,2xb1bfs.,,";
  int pos = isLetter(aa);
  aa = aa.Substring(pos, 1);
  Console.WriteLine(aa.ToUpper());
  Console.Read();
 }
 public static int isLetter(string validString)
 {
  byte[] tempbyte = System.Text.Encoding.Default.GetBytes(validString);
  int pos = 0;
  for (int i = 0; i < validString.Length; i++)
  {
   byte by = tempbyte[i];
   if ((by >= 65) && (by <= 90) || ((by >= 97) && (by <= 122)))
   {
    break;
   }
   pos++;
  }
  return pos;
 }
}

希望本文所述对大家C#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com