com.aspose.words

Class FindReplaceOptions

  • java.lang.Object
    • com.aspose.words.FindReplaceOptions
public class FindReplaceOptions 
extends java.lang.Object

Specifies options for find/replace operations.

Example:

Simple find and replace operation.
// Open the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("Hello _CustomerName_,");

// Check the document contains what we are about to test.
System.out.println(doc.getFirstSection().getBody().getParagraphs().get(0).getText());

FindReplaceOptions options = new FindReplaceOptions();
options.setMatchCase(false);
options.setFindWholeWordsOnly(false);

// Replace the text in the document.
doc.getRange().replace("_CustomerName_", "James Bond", options);

// Save the modified document.
doc.save(getMyDir() + "\\Artifacts\\Range.ReplaceSimple.docx");

Constructor Summary
FindReplaceOptions(intdirection)
FindReplaceOptions(intdirection, IReplacingCallback replacingCallback)
 
Property Getters/Setters Summary
FontgetApplyFont()
Text formatting applied to new content.
ParagraphFormatgetApplyParagraphFormat()
Paragraph formatting applied to new content.
intgetDirection()
void
setDirection(intvalue)
           Selects direction for replace. Default value is FindReplaceDirection.FORWARD. The value of the property is FindReplaceDirection integer constant.
booleangetFindWholeWordsOnly()
void
setFindWholeWordsOnly(booleanvalue)
           True indicates the oldValue must be a standalone word.
booleangetMatchCase()
void
setMatchCase(booleanvalue)
           True indicates case-sensitive comparison, false indicates case-insensitive comparison.
booleangetPreserveMetaCharacters()
void
           True indicates that meta-characters beginning with "&" are preserved. Default value is false.
IReplacingCallbackgetReplacingCallback()
void
           The user-defined method which is called before every replace occurrence.
 

    • Constructor Detail

      • FindReplaceOptions

        public FindReplaceOptions()
      • FindReplaceOptions

        public FindReplaceOptions(int direction)
        Parameters:
        direction - A FindReplaceDirection value.
    • Property Getters/Setters Detail

      • getApplyFont

        public Font getApplyFont()
        
        Text formatting applied to new content.
      • getApplyParagraphFormat

        public ParagraphFormat getApplyParagraphFormat()
        
        Paragraph formatting applied to new content.
      • getDirection/setDirection

        public int getDirection() / public void setDirection(int value)
        
        Selects direction for replace. Default value is FindReplaceDirection.FORWARD. The value of the property is FindReplaceDirection integer constant.
      • getFindWholeWordsOnly/setFindWholeWordsOnly

        public boolean getFindWholeWordsOnly() / public void setFindWholeWordsOnly(boolean value)
        
        True indicates the oldValue must be a standalone word.

        Example:

        Simple find and replace operation.
        // Open the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Hello _CustomerName_,");
        
        // Check the document contains what we are about to test.
        System.out.println(doc.getFirstSection().getBody().getParagraphs().get(0).getText());
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(false);
        
        // Replace the text in the document.
        doc.getRange().replace("_CustomerName_", "James Bond", options);
        
        // Save the modified document.
        doc.save(getMyDir() + "\\Artifacts\\Range.ReplaceSimple.docx");
      • getMatchCase/setMatchCase

        public boolean getMatchCase() / public void setMatchCase(boolean value)
        
        True indicates case-sensitive comparison, false indicates case-insensitive comparison.

        Example:

        Simple find and replace operation.
        // Open the document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Hello _CustomerName_,");
        
        // Check the document contains what we are about to test.
        System.out.println(doc.getFirstSection().getBody().getParagraphs().get(0).getText());
        
        FindReplaceOptions options = new FindReplaceOptions();
        options.setMatchCase(false);
        options.setFindWholeWordsOnly(false);
        
        // Replace the text in the document.
        doc.getRange().replace("_CustomerName_", "James Bond", options);
        
        // Save the modified document.
        doc.save(getMyDir() + "\\Artifacts\\Range.ReplaceSimple.docx");
      • getPreserveMetaCharacters/setPreserveMetaCharacters

        public boolean getPreserveMetaCharacters() / public void setPreserveMetaCharacters(boolean value)
        
        True indicates that meta-characters beginning with "&" are preserved. Default value is false.
      • getReplacingCallback/setReplacingCallback

        public IReplacingCallback getReplacingCallback() / public void setReplacingCallback(IReplacingCallback value)
        
        The user-defined method which is called before every replace occurrence.