首页 > 解决方案 > .NET String.Split 对于非拉丁字符出现故障

问题描述

试图将段落分成句子:我的文本是混合拉丁和亚美尼亚字母字符;当我调用 String.Split 时,拆分位置错误。我试图拆分句号/问号/感叹号。这可能是 .NET 中的错误吗?还是我错过了什么?

链接到 DotNetFiddle。如果您运行该代码,您会看到第一句话是“The Temple of Garni(亚美尼亚语:Գառնիիտաճար”,这是错误的,它只是第一句话的一部分。

    string combinedParas = @"The Temple of Garni (Armenian: Գառնիի տաճար, Gaṙnii tačar, [ˈgɑrnii ˈtɑtʃɑʁ])[a] is the only standing Greco-Roman colonnaded building in Armenia and the former Soviet Union. Built in the Ionic order in the village of Garni, Armenia, it is the best-known structure and symbol of pre-Christian Armenia.";

    var sentences = combinedParas.Split(new[] { ',', '?', '!' }, StringSplitOptions.RemoveEmptyEntries);
    foreach(var s in sentences) {
        Console.WriteLine(s);

主要是出于好奇而询问;我已经继续前进并编写了自己的拆分函数来处理手头的问题。

标签: .netstring

解决方案


推荐阅读