I'm working on a conversion project from java to c#, is there any c# equivalent for BreakIterator
? I was trying IEnumerator
, but cannot find iterator.SetText()
usage below, can anyone suggest equivalent C# code for below lines:
String finalResult=""
ArrayList<String> resultList = new ArrayList<String>();
BreakIterator iterator = BreakIterator.getSentenceInstance(currentLocale);
//int counter = 0;
iterator.setText(finalResult);
int lastIndex = iterator.first();
while (lastIndex != BreakIterator.DONE)
{
int firstIndex = lastIndex;
lastIndex = iterator.next();
if (lastIndex != BreakIterator.DONE)
{
String sentence = finalResult.substring(firstIndex, lastIndex);
resultList.add(sentence);
System.out.println("sentence = " + sentence);
//counter++;
}
}
BreakIterator
is a mechanism for supporting locale-aware boundary analysis on arbitrary strings of Unicode text. I suspect the Java class is heavily based on (perhaps even directly dependent on, but I'm speculating) the ICU (International Components for Unicode) project: http://site.icu-project.org/To quote the ICU docs:
ICU provides C language bindings, aptly named ICU4C. The ICU FAQ describes ICU4C:
SIL International provides C# language bindings, which allow you to use ICU4C in C# applications, via a project named icu-dotnet.
You can find the official icu-dotnet repository on Github:
https://github.com/sillsdev/icu-dotnet
Or, install it via Nuget:
https://www.nuget.org/packages/icu.net/