6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

文字数を数える

Posted at
Program.cs

static int GetLength( string value )
{
    return value.Length;
}

static int GetLengthInTextElements( string value )
{
    var sinfo = new StringInfo( value );
    return sinfo.LengthInTextElements;
}

static void Main( string[ ] args )
{
    var str = "𠮟咤する";
    Console.WriteLine( "Length: {0}", GetLength( str ) );
    Console.WriteLine( "LengthInTextElements: {0}", GetLengthInTextElements( str ) );
}

標準出力

Length: 5
LengthInTextElements: 4

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?