「C#」文字列の先頭の文字だけを大文字に変換するサンプル

構文
string 変数名 = 値
char.ToUpper(変数名[0])
文字列を配列として取得します。
ToUpper関数を利用して文字列の先頭だけ大文字に変換します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
namespace StudyDemo
{
class Program
{
static void Main(string[] args)
{
string cft = "arkgame";
Console.WriteLine( char.ToUpper(cft[0]) + cft.Substring(1) );
}
}
}
using System; namespace StudyDemo { class Program { static void Main(string[] args) { string cft = "arkgame"; Console.WriteLine( char.ToUpper(cft[0]) + cft.Substring(1) ); } } }
using System;

namespace StudyDemo
{
  class Program
  {
    static void Main(string[] args)
    {
            string cft = "arkgame";

            Console.WriteLine( char.ToUpper(cft[0]) + cft.Substring(1) );
    }
  }
}

実行結果
Arkgame

C#

Posted by arkgame