C# 文字列の文字数を表示する

C#で、Lengthを使用して、文字列の文字数を表示するサンプルコードを記述してます。
環境
- OS windows10 pro 64bit
- Microsoft Visual Studio Community 2019 Version 16.7.1
Length使い方
Lengthを使用すると、文字列の文字数を取得することが可能です。
ここでは、アルファベットと平仮名と漢字で生成された文字列の文字数を取得してます。
using System;
using System.Collections.Generic;
namespace testapp
{
class Program
{
static void Main(string[] args)
{
string str = "MEBEE";
Console.WriteLine(str.Length);
// 5
str = "あいうえお";
Console.WriteLine(str.Length);
// 5
str = "本日は晴天";
Console.WriteLine(str.Length);
// 5
Console.ReadKey();
}
}
}
-
前の記事
Ruby 別の配列同士を1つにまとめる 2021.01.04
-
次の記事
python 同じ文字列を繰り返して結合する 2021.01.04
コメントを書く