在 *.docx 文件中使用这样的文本:
I scream. You scream. We all scream for ice cream. I scream.You scream.We all scream for ice cream.
...(IOW,第一种情况下句子之间有两个空格,第二种情况下没有空格)我想在句子之间强制一个且只有一个空格,所以它最终像这样:
I scream. You scream. We all scream for ice cream. I scream. You scream. We all scream for ice cream.
但是这段代码:
// 65..90 are A..Z; 97..122 are a..z
const int firstCapPos = 65;
const int lastCapPos = 90;
const int firstLowerPos = 97;
const int lastLowerPos = 122;
. . .
// This will change sentences like this: "I scream.You scream.We all scream of ice cream." ...to this: "I scream. You scream. We all scream of ice cream."
private void SpacifySardinizedLetters(string filename)
{
using (DocX document = DocX.Load(filename))
{
for (int i = firstCapPos; i <= lastCapPos; i++)
{
char c = (char)i;
string originalStr = string.Format(".{0}", c);
string newStr = string.Format(". {0}", c);
document.ReplaceText(originalStr, newStr);
}
for (int i = firstLowerPos; i <= lastLowerPos; i++)
{
char c = (char)i;
string originalStr = string.Format(".{0}", c);
string newStr = string.Format(". {0}", c);
document.ReplaceText(originalStr, newStr);
}
document.Save();
}
}
// This will change sentences like this: "I scream. You scream. We all scream of ice cream." ...to this: "I scream. You scream. We all scream of ice cream."
private void SnuggifyLooseyGooseySentenceEndings(string filename)
{
using (DocX document = DocX.Load(filename))
{
for (int i = firstCapPos; i <= lastCapPos; i++)
{
char c = (char)i;
string originalStr = string.Format(". {0}", c);
string newStr = string.Format(". {0}", c);
document.ReplaceText(originalStr, newStr);
}
for (int i = firstLowerPos; i <= lastLowerPos; i++)
{
char c = (char)i;
string originalStr = string.Format(". {0}", c);
string newStr = string.Format(". {0}", c);
document.ReplaceText(originalStr, newStr);
}
document.Save();
}
}
...仅适用于紧缩在一起的句子-它们之间有两个空格的句子无法更改。为什么?我的代码或 docx 库中是否有错误?