*.docx ファイルで次のようなテキストを使用します。
I scream. You scream. We all scream for ice cream. I scream.You scream.We all scream for ice cream.
...(IOW、最初のケースでは文の間に2つのスペース、2番目のケースではスペースなし)文の間に1つだけのスペースを強制したいので、次のようになります。
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();
}
}
...くしゃくしゃになった文でのみ機能します - 間に2つのスペースがあるものは変更できません。なんで?コードまたは docx ライブラリにバグはありますか?