c# - 如何删除使用 string.Replace ("-", ""后剩余的空间)

标签 c# .net

我已经使用 PDFBox 将 PDF 文档转换为文本。但是,许多单词用破折号分成 2 行。

例如,单词Others变为Others,单词becoming变为be-coming

如果我使用 string.Replace 将“-”替换为空字符串,它会将单词之间用空格分隔开。

在C#中有没有办法去掉单词中间的破折号,把单词的各个部分重新拼接成一个单词?

最佳答案

我写了这个单元测试,破折号被正确删除了。

[TestMethod]
public void ReplaceDashByEmptyString()
{
    string othersWithDash = "Oth-ers";

    string othersWithoutDash = othersWithDash.Replace("-", string.Empty);

    Assert.AreEqual("Others", othersWithoutDash);
}

关于c# - 如何删除使用 string.Replace ("-", ""后剩余的空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15800867/

相关文章:

c# - 在 UWP 中的辅助监视器上打开新窗口

c# - 如何按值中的子字符串对 Dictionary<string,string> 进行排序?

c# - Validator 未识别 RegularExpression 数据注释

c# - Expression.Call GroupBy 然后 Select 和 Count()?

c# - 将带有符号的货币转换为十进制

.net - 在 WPF : Children. 中移除或 Children.Clear 不会释放对象

c# - 将所有用户及其角色放入表中 asp.net mvc

c# - EndRead引发IO异常

c# - 被 OverflowException 击中

c# - 如何计算 WPF 可视元素的逻辑宽度?