# C full and half Angle conversion and simple code for judging

• 2020-05-17 06:15:20
• OfStack

1. Judge whether it is full Angle and half Angle
All Angle to take up two half Angle takes up one byte by byte string. length and System text. Encoding. Default. GetByteCount including string. length said a string of characters,
System. text. Encoding. Default. GetByteCount said the number of bytes of the string.
Judge the half Angle (if it is half Angle, true)
As follows:
``````
if (checkString.Length == Encoding.Default.GetByteCount(checkString)) { return true; } else { return false; }
``````

Full Angle (full Angle returns true)
As follows:
``````
if (2 * checkString.Length == Encoding.Default.GetByteCount(checkString)) { return true; } else { return false; }
``````

2. Full Angle half Angle conversion
``````
#region  Full Angle half Angle conversion
/// <summary>
///  It's a function of the total Angle of rotation (SBC case)
/// </summary>
/// <param name="input"> Arbitrary string </param>
/// <returns> Full Angle string </returns>
///<remarks>
/// The full space is 12288 , half corner space is 32
/// Other characters are half corners (33-126) With the Angle of (65281-65374) The corresponding relation is: mean difference 65248
///</remarks>
public  static string ToSBC(string input)
{
// Half Angle to full Angle:
char[] c=input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i]==32)
{
c[i]=(char)12288;
continue;
}
if (c[i]<127)
c[i]=(char)(c[i]+65248);
}
return new string(c);
}
/// <summary>  It's a function of the half Angle (DBC case) </summary>
/// <param name="input"> Arbitrary string </param>
/// <returns> Half Angle string </returns>
///<remarks>
/// The full space is 12288 , half corner space is 32
/// Other characters are half corners (33-126) With the Angle of (65281-65374) The corresponding relation is: mean difference 65248
///</remarks>
public static string ToDBC(string input)
{
char[] c=input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i]==12288)
{
c[i]= (char)32;
continue;
}
if (c[i]>65280 && c[i]<65375)
c[i]=(char)(c[i]-65248);
}
return new string(c);
}
#endregion
``````

Related articles: