SoFunction
Updated on 2025-03-01

Implementation code for determining whether a string is full or half-width in C#

The full-width of a C# string refers to a character represented by two bytes.

A half-width of a C# string is a character represented by a byte

In this way, we can use and to judge

The number of characters representing the C# string string,

Represents the number of bytes of a string.

The half-width is judged as follows:

Copy the codeThe code is as follows:

if ( == (checkString))
{      
   return true;     
}    
else   
{     
   return false;    
}

The full angle of judgment is as follows:
Copy the codeThe code is as follows:

if (2 * == (checkString)) 
 {     
   return true;  
 }    
 else   
 {     
   return false;   
}

This achieves the purpose of judging whether a C# string is full or half-width.