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

C#で、Lengthを使用して、文字列の文字数を表示するサンプルコードを記述してます。
環境
- OS windows10 pro 64bit
- Microsoft Visual Studio Community 2019 Version 16.7.1
Length使い方
Lengthを使用すると、文字列の文字数を取得することが可能です。
ここでは、アルファベットと平仮名と漢字で生成された文字列の文字数を取得してます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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
コメントを書く