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# - 我没有 SqlServerCe 程序集?

c# - Entity Framework 更新问题

c# - 网络浏览器 : simulate mouse click on ul-li item in webpage

c# - MSBuild 条件编译

c# - MySQL日期格式问题

c# - System.InvalidOperationException' 出现在 AutoMapper.dll 中。附加信息 : Mapper not initialized

c# - 从 API 请求中删除 Arrafinity Cookie

c# - Windows 窗体 MSN Messenger 登录

c# - 日期时间有太多小数位

c# - .Net - 传递可变数量的参数