SoFunction
Updated on 2025-03-07

c# Example code for getting string width (byte number method)

 int totalCount = 0;
 string mSubStr = "";
  for (int i = 0; i < ; i++)
 {
  string mChar = (i, 1);
   int byteCount = (mChar);
   if (byteCount == 1) 
   { 
    totalCount++;
   mSubStr += mChar;
    if (totalCount == charNumber || i == - 1)
    {
     (mSubStr);
     totalCount = 0;
     mSubStr = "";
    } 
   } 
   else if (byteCount > 1) 
   {  
    totalCount += 2;
    if (totalCount > charNumber ) 
    { 
     (mSubStr);
     if (i == - 1) 
     {
      mSubStr = mChar;
      (mSubStr);
     }
     else
     {
      totalCount = 2;
      mSubStr = mChar;
     } 
    } 
    else if (totalCount == charNumber) 
    {
     mSubStr += mChar;
     (mSubStr);
     totalCount = 0;
     mSubStr = "";
    }
    else if (i == - 1)
    { 
     mSubStr += mChar;
     (mSubStr);
    }
    else 
    { 
     mSubStr += mChar;
    } 
   } 
  } 
  return resultList;
}