30
1
using System;
2
using System.Collections.Generic;
3
using System.Globalization;
4
using System.Linq;
5
6
public class Program
7
{
8
public static void Main()
9
{
10
var s = "Les Mise\u0301rables";
11
var r = s.ReverseGraphemeClusters();
12
Console.WriteLine(r);
13
}
14
}
15
16
// From: http://stackoverflow.com/questions/228038/best-way-to-reverse-a-string
17
// Answer by: R. Martinho Fernandes.
18
public static class StringEx
19
{
20
private static IEnumerable<string> GraphemeClusters(this string s) {
21
var enumerator = StringInfo.GetTextElementEnumerator(s);
22
while(enumerator.MoveNext()) {
23
yield return (string)enumerator.Current;
24
}
25
}
26
27
public static string ReverseGraphemeClusters(this string s) {
28
return string.Join("", s.GraphemeClusters().Reverse().ToArray());
29
}
30
}
Cached Result