fork(1) download
  1. using System;
  2. using System.IO;
  3. using System.Globalization;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var text = "1234🔹67890";
  10. var maxChars = 6;
  11. Console.WriteLine("maxChars: {0}", maxChars);
  12. var newStr = new StringInfo(text).SubstringByTextElements(0, maxChars);
  13. Console.WriteLine("newStr.Length: {0}, LengthInTextElements: {1}, maxChars: {2}",
  14. newStr.Length, new StringInfo(newStr).LengthInTextElements, maxChars);
  15. }
  16. }
Success #stdin #stdout 0.03s 16260KB
stdin
Standard input is empty
stdout
maxChars: 6
newStr.Length: 7, LengthInTextElements: 6, maxChars: 6