本文整理汇总了C#中Range.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Range.Delete方法的具体用法?C# Range.Delete怎么用?C# Range.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Range
的用法示例。
在下文中一共展示了Range.Delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRangeDeleteAll
public void TestRangeDeleteAll()
{
HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile);
Range range = daDoc.GetRange();
Assert.AreEqual(1, range.NumSections);
Section section = range.GetSection(0);
Assert.AreEqual(5, section.NumParagraphs);
Paragraph para = section.GetParagraph(2);
String text = para.Text;
Assert.AreEqual(originalText, text);
bool keepLooking = true;
while (keepLooking)
{
// Reload the range every time
range = daDoc.GetRange();
int offset = range.Text.IndexOf(searchText);
if (offset >= 0)
{
int absOffset = range.StartOffset + offset;
Range subRange = new Range(
absOffset, (absOffset + searchText.Length), range.GetDocument());
Assert.AreEqual(searchText, subRange.Text);
subRange.Delete();
}
else
{
keepLooking = false;
}
}
// we need to let the model re-calculate the Range before we use it
range = daDoc.GetRange();
Assert.AreEqual(1, range.NumSections);
section = range.GetSection(0);
Assert.AreEqual(5, section.NumParagraphs);
para = section.GetParagraph(0);
text = para.Text;
Assert.AreEqual(introText, text);
para = section.GetParagraph(1);
text = para.Text;
Assert.AreEqual(expectedText1, text);
para = section.GetParagraph(2);
text = para.Text;
Assert.AreEqual(expectedText2, text);
para = section.GetParagraph(3);
text = para.Text;
Assert.AreEqual(expectedText3, text);
}
示例2: Delete
public void Delete(int start, int length)
{
Range r = new Range(start, start + length, this);
r.Delete();
}
示例3: TestRangeDeleteOne
public void TestRangeDeleteOne()
{
HWPFDocument daDoc = HWPFTestDataSamples.OpenSampleFile(illustrativeDocFile);
Range range = daDoc.GetOverallRange();
Assert.AreEqual(1, range.NumSections);
Section section = range.GetSection(0);
Assert.AreEqual(5, section.NumParagraphs);
Paragraph para = section.GetParagraph(2);
String text = para.Text;
Assert.AreEqual(originalText, text);
int offset = text.IndexOf(searchText);
Assert.AreEqual(192, offset);
int absOffset = para.StartOffset + offset;
Range subRange = new Range(absOffset, (absOffset + searchText.Length), para.GetDocument());
Assert.AreEqual(searchText, subRange.Text);
subRange.Delete();
// we need to let the model re-calculate the Range before we Evaluate it
range = daDoc.GetRange();
Assert.AreEqual(1, range.NumSections);
section = range.GetSection(0);
Assert.AreEqual(5, section.NumParagraphs);
para = section.GetParagraph(2);
text = para.Text;
Assert.AreEqual(expectedText2, text);
// this can lead to a StringBuilderOutOfBoundsException, so we will add it
// even though we don't have an assertion for it
Range daRange = daDoc.GetRange();
text = daRange.Text;
}