With text like this in a *.docx file:
I scream. You scream. We all scream for ice cream. I scream.You scream.We all scream for ice cream.
...(IOW, two spaces between sentences in the first case, and no spaces in the second case) I want to force one and only one space between the sentences, so it ends up like so:
I scream. You scream. We all scream for ice cream. I scream. You scream. We all scream for ice cream.
But this code:
// 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();
}
}
...only works for the scrunched together sentences - The ones with two spaces between them fails to change. Why? Is there a bug in my code, or in the docx library?
I did what I said in my comment, downloaded DocX, created a Microsoft Word document and ran this code from a project referencing the DocX library:
And the Word file, prior containing:
Afterwards contains:
So, works for me.
Edit: I ran your code on a file containing the first line from your question, and it works. Are you sure you're running this code and that you're looking at the correct file?