Implement StringReverse method

This commit is contained in:
Petr Pucil 2020-03-21 22:41:30 +01:00
parent 152ddd9dd8
commit d62f34fcad
1 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Globalization;
namespace Kaitai
{
@ -678,6 +679,22 @@ namespace Kaitai
}
}
/// <summary>
/// Reverses the string, Unicode-aware.
/// </summary>
/// <a href="https://stackoverflow.com/a/15029493">taken from here</a>
public static string StringReverse(string s)
{
TextElementEnumerator enumerator = StringInfo.GetTextElementEnumerator(s);
List<string> elements = new List<string>();
while (enumerator.MoveNext())
elements.Add(enumerator.GetTextElement());
elements.Reverse();
return string.Concat(elements);
}
#endregion
}
}