<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fediting_text_documents</id>
	<title>EN/documentation/basic guide/editing text documents - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fediting_text_documents"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/editing_text_documents&amp;action=history"/>
	<updated>2026-11-11T13:55:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/editing_text_documents&amp;diff=15953&amp;oldid=prev</id>
		<title>Sancho: Основной текст</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/editing_text_documents&amp;diff=15953&amp;oldid=prev"/>
		<updated>2011-09-02T17:16:09Z</updated>

		<summary type="html">&lt;p&gt;Основной текст&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Editing Text Documents&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&lt;br /&gt;
{{Documentation/BASICGuideTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=EN/documentation/basic_guide/structure_of_text_documents&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/more_than_text&lt;br /&gt;
|textdocs=block&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
&lt;br /&gt;
The previous section has already discussed a whole range of options for editing text documents, focusing on the &amp;lt;idl&amp;gt;com.sun.star.text.TextPortion&amp;lt;/idl&amp;gt; and &amp;lt;idl&amp;gt;com.sun.star.text.Paragraph&amp;lt;/idl&amp;gt; services, which grant access to paragraph portions as well as paragraphs. These services are appropriate for applications in which the content of a text is to be edited in one pass through a loop. However, this is not sufficient for many problems. {{OOo}} provides the &amp;lt;idl&amp;gt;com.sun.star.text.TextCursor&amp;lt;/idl&amp;gt; service for more complicated tasks, including navigating backward within a document or navigating based on sentences and words rather than &amp;lt;tt&amp;gt;TextPortions&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== The TextCursor ==&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; in the {{OOo}} API is comparable with the visible cursor used in a {{OOo}} document. It marks a certain point within a text document and can be navigated in various directions through the use of commands. The &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; objects available in {{OOo}} Basic should not, however, be confused with the visible cursor. These are two very different things.&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|Terminology differs from that used in VBA: In terms of scope of function, the Range object from VBA can be compared with the TextCursor object in {{OOo}} and not — as the name possibly suggests — with the Range object in {{OOo}}.}}&lt;br /&gt;
&lt;br /&gt;
The TextCursor object in {{OOo}}, for example, provides methods for navigating and changing text which are included in the Range object in VBA (for example, MoveStart, MoveEnd, InsertBefore, InsertAfter). The corresponding counterparts of the TextCursor object in {{OOo}} are described in the following sections.&lt;br /&gt;
&lt;br /&gt;
=== Navigating within a Text  ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; object in {{OOo}} Basic acts independently from the visible cursor in a text document. A program-controlled position change of a &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; object has no impact whatsoever on the visible cursor. Several &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; objects can even be opened for the same document and used in various positions, which are independent of one another. &lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; object is created using the &amp;lt;tt&amp;gt;createTextCursor&amp;lt;/tt&amp;gt; call: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object&lt;br /&gt;
Dim Cursor As Object&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Cursor = Doc.Text.createTextCursor()&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
The Cursor object created in this way supports the &amp;lt;tt&amp;gt;com.sun.star.text.TextCursor&amp;lt;/tt&amp;gt; service, which in turn provides a whole range of methods for navigating within text documents. The following example first moves the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; ten characters to the left and then three characters to the right: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;Cursor.goLeft(10, False)&lt;br /&gt;
Cursor.goRight(3, False)&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
A &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; can highlight a complete area. This can be compared with highlighting a point in the text using the mouse. The &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; parameter in the previous function call specifies whether the area passed over with the cursor movement is highlighted. For example, the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; in the following example &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Cursor.goRight(10, False)&lt;br /&gt;
Cursor.goLeft(3, True)&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
first moves ten characters to the right without highlighting, and then moves back three characters and highlights this. The area highlighted by the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; therefore begins after the seventh character in the text and ends after the tenth character. &lt;br /&gt;
&lt;br /&gt;
Here are the central methods that the &amp;lt;idl&amp;gt;com.sun.star.text.TextCursor&amp;lt;/idl&amp;gt; service provides for navigation: &lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;goLeft (Count, Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps Count characters to the left. &lt;br /&gt;
;&amp;lt;tt&amp;gt;goRight (Count, Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps Count characters to the right. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoStart (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the text document. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoEnd (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the end of the text document. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoRange (TextRange, Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the specified &amp;lt;tt&amp;gt;TextRange&amp;lt;/tt&amp;gt;-Object. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoStartOfWord (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the current word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoEndOfWord (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the end of the current word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoNextWord (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the next word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoPreviousWord (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the previous word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isStartOfWord ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the start of a word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isEndOfWord ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the end of a word. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoStartOfSentence (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the current sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoEndOfSentence (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the end of the current sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoNextSentence (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the next sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoPreviousSentence (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the previous sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isStartOfSentence ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the start of a sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isEndOfSentence ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the end of a sentence. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoStartOfParagraph (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the current paragraph. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoEndOfParagraph (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the end of the current paragraph. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoNextParagraph (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the next paragraph. &lt;br /&gt;
;&amp;lt;tt&amp;gt;gotoPreviousParagraph (Expand)&amp;lt;/tt&amp;gt; &lt;br /&gt;
:jumps to the start of the previous paragraph. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isStartOfParagraph ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the start of a paragraph. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isEndOfParagraph ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; is at the end of a paragraph.&lt;br /&gt;
&lt;br /&gt;
The text is divided into sentences on the basis of sentence symbols. Periods  are, for example, interpreted as symbols indicating the end of sentences. (In English, at least, they must be followed by a space, tab, or return for this to work.) &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Expand&amp;lt;/tt&amp;gt; parameter is a Boolean value which specifies whether the area passed over during navigation is to be highlighted. All navigation methods furthermore return a Boolean parameter which specifies whether the navigation was successful or whether the action was terminated for lack of text. &lt;br /&gt;
&lt;br /&gt;
The following is a list of several methods for editing highlighted areas using a &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; and which also support the &amp;lt;idl&amp;gt;com.sun.star.text.TextCursor&amp;lt;/idl&amp;gt; service: &lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;collapseToStart ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:resets the highlighting and positions the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; at the start of the previously highlighted area. &lt;br /&gt;
;&amp;lt;tt&amp;gt;collapseToEnd ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:resets the highlighting and positions the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; at the end of the previously highlighted area. &lt;br /&gt;
;&amp;lt;tt&amp;gt;isCollapsed ()&amp;lt;/tt&amp;gt; &lt;br /&gt;
:returns &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; if the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; does not cover any highlighting at present.&lt;br /&gt;
&lt;br /&gt;
=== Formatting Text with TextCursor ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;idl&amp;gt;com.sun.star.text.TextCursor&amp;lt;/idl&amp;gt; service supports all the character and paragraph properties that were presented at the start of this chapter. &lt;br /&gt;
&lt;br /&gt;
The following example shows how these can be used in conjunction with a &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt;. It passes through a complete document and formats the first word of every sentence in bold type. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object   &lt;br /&gt;
Dim Cursor As Object&lt;br /&gt;
Dim Proceed As Boolean&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Cursor = Doc.Text.createTextCursor&lt;br /&gt;
&lt;br /&gt;
Do &lt;br /&gt;
  Cursor.gotoEndOfWord(True)&lt;br /&gt;
  Cursor.CharWeight = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
  Proceed = Cursor.gotoNextSentence(False)&lt;br /&gt;
  Cursor.gotoNextWord(False)&lt;br /&gt;
Loop While Proceed &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example first creates a document object for the text that has just been opened. Then it iterates through the entire text, sentence by sentence, and highlights each of the first words and formats this in bold.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving and Modifying Text Contents ===&lt;br /&gt;
&lt;br /&gt;
If a &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; contains a highlighted area, then this text is available by means of the &amp;lt;tt&amp;gt;String&amp;lt;/tt&amp;gt; property of the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; object. The following example uses the &amp;lt;tt&amp;gt;String&amp;lt;/tt&amp;gt; property to display the first words of a sentence in a message box:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object   &lt;br /&gt;
Dim Cursor As Object&lt;br /&gt;
Dim Proceed As Boolean&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Cursor = Doc.Text.createTextCursor&lt;br /&gt;
&lt;br /&gt;
Do &lt;br /&gt;
  Cursor.gotoEndOfWord(True)&lt;br /&gt;
  MsgBox Cursor.String&lt;br /&gt;
  Proceed = Cursor.gotoNextSentence(False)&lt;br /&gt;
  Cursor.gotoNextWord(False)&lt;br /&gt;
Loop While Proceed &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first word of each sentence can be modified in the same way using the &amp;lt;tt&amp;gt;String&amp;lt;/tt&amp;gt; property: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object   &lt;br /&gt;
Dim Cursor As Object&lt;br /&gt;
Dim Proceed As Boolean&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Cursor = Doc.Text.createTextCursor&lt;br /&gt;
&lt;br /&gt;
Do &lt;br /&gt;
  Cursor.gotoEndOfWord(True)&lt;br /&gt;
  Cursor.String = &amp;quot;Ups&amp;quot;&lt;br /&gt;
  Proceed = Cursor.gotoNextSentence(False)&lt;br /&gt;
  Cursor.gotoNextWord(False)&lt;br /&gt;
Loop While Proceed &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; contains a highlighted area, an assignment to the &amp;lt;tt&amp;gt;String&amp;lt;/tt&amp;gt; property replaces this with the new text. If there is no highlighted area, the text is inserted at the present &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; position.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Control Codes ===&lt;br /&gt;
&lt;br /&gt;
In some situations, it is not the actual text of a document, but rather its structure that needs modifying. {{OOo}} provides control codes for this purpose. These are inserted in the text and influence its structure. The control codes are defined in the &amp;lt;idl&amp;gt;com.sun.star.text.ControlCharacter&amp;lt;/idl&amp;gt; group of constants. The following control codes are available in {{OOo}}:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;PARAGRAPH_BREAK&amp;lt;/tt&amp;gt;:paragraph break.&lt;br /&gt;
;&amp;lt;tt&amp;gt;LINE_BREAK&amp;lt;/tt&amp;gt;:line break within a paragraph.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SOFT_HYPHEN&amp;lt;/tt&amp;gt;:possible point for syllabification.&lt;br /&gt;
;&amp;lt;tt&amp;gt;HARD_HYPHEN&amp;lt;/tt&amp;gt;:obligatory point for syllabification.&lt;br /&gt;
;&amp;lt;tt&amp;gt;HARD_SPACE&amp;lt;/tt&amp;gt;:protected space that is not spread out or compressed in justified text.&lt;br /&gt;
&lt;br /&gt;
To insert the control codes, you need not only the cursor but also the associated text document objects. The following example inserts a paragraph after the 20th character of a text:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object   &lt;br /&gt;
Dim Cursor As Object&lt;br /&gt;
Dim Proceed As Boolean&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Cursor = Doc.Text.createTextCursor&lt;br /&gt;
Cursor.goRight(20, False)&lt;br /&gt;
Doc.Text.insertControlCharacter(Cursor, _&lt;br /&gt;
    com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;False&amp;lt;/tt&amp;gt; parameter in the call of the &amp;lt;tt&amp;gt;insertControlCharacter&amp;lt;/tt&amp;gt; method ensures that the area currently highlighted by the &amp;lt;tt&amp;gt;TextCursor&amp;lt;/tt&amp;gt; remains after the insert operation. If the &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt; parameter is passed here, then &amp;lt;tt&amp;gt;insertControlCharacter&amp;lt;/tt&amp;gt; replaces the current text.&lt;br /&gt;
&lt;br /&gt;
== Searching for Text Portions ==&lt;br /&gt;
&lt;br /&gt;
In many instances, it is the case that a text is to be searched for a particular term and the corresponding point needs to be edited. All {{OOo}} documents provide a special interface for this purpose, and this interface always functions in accordance with the same principle: Before a search process, what is commonly referred to as a &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; must first be created. This defines what {{OOo}} searches for in a document. A &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; is an object which supports the &amp;lt;tt&amp;gt;com.sun.star.util.&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; service and can be created by means of the &amp;lt;tt&amp;gt;createSearchDescriptor&amp;lt;/tt&amp;gt; method of a document: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim SearchDesc As Object&lt;br /&gt;
SearchDesc = Doc.createSearchDescriptor&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; has been created, it receives the text to be searched for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
SearchDesc.searchString=&amp;quot;any text&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In terms of its function, the &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; is best compared with the search dialog from {{OOo}}. In a similar way to the search window, the settings needed for a search can be set in the &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; object. &lt;br /&gt;
&lt;br /&gt;
The properties are provided by the &amp;lt;idl&amp;gt;com.sun.star.util.SearchDescriptor&amp;lt;/idl&amp;gt; service: &lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchBackwards (Boolean)&amp;lt;/tt&amp;gt;:searches through the text backward rather than forward.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchCaseSensitive (Boolean)&amp;lt;/tt&amp;gt;:takes uppercase and lowercase characters into consideration during the search.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchRegularExpression (Boolean)&amp;lt;/tt&amp;gt;:treats the search expression like a regular expression.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchStyles (Boolean)&amp;lt;/tt&amp;gt;:searches through the text for the specified paragraph template.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchWords (Boolean)&amp;lt;/tt&amp;gt;:only searches for complete words.&lt;br /&gt;
&lt;br /&gt;
The {{OOo}} &amp;lt;tt&amp;gt;SearchSimilarity&amp;lt;/tt&amp;gt; (or “fuzzy match”) function is also available in {{OOo}} Basic. With this function, {{OOo}} searches for an expression that may be similar to but not exactly the same as the search expression. The number of additional, deleted and modified characters for these expressions can be defined individually. Here are the associated properties of the &amp;lt;tt&amp;gt;com.sun.star.util.SearchDescriptor&amp;lt;/tt&amp;gt; service:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchSimilarity (Boolean)&amp;lt;/tt&amp;gt;:performs a similarity search.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchSimilarityAdd (Short)&amp;lt;/tt&amp;gt;:number of characters which may be added for a similarity search.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchSimilarityExchange (Short)&amp;lt;/tt&amp;gt;:number of characters which may be replaced as part of a similarity search.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchSimilarityRemove (Short)&amp;lt;/tt&amp;gt;:number of characters which may be removed as part of a similarity search.&lt;br /&gt;
;&amp;lt;tt&amp;gt;SearchSimilarityRelax (Boolean)&amp;lt;/tt&amp;gt;:takes all deviation rules into consideration at the same time for the search expression.&lt;br /&gt;
&lt;br /&gt;
Once the &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; has been prepared as requested, it can be applied to the text document. The {{OOo}} documents provide the &amp;lt;tt&amp;gt;findFirst&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;findNext&amp;lt;/tt&amp;gt; methods for this purpose: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Found = Doc.findFirst (SearchDesc)&lt;br /&gt;
&lt;br /&gt;
Do Until IsNull(Found)&lt;br /&gt;
  ' Edit search results...&lt;br /&gt;
  Found = Doc.findNext( Found.End, SearchDesc)&lt;br /&gt;
Loop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example finds all matches in a loop and returns a &amp;lt;tt&amp;gt;TextRange&amp;lt;/tt&amp;gt; object, which refers to the found text passage.&lt;br /&gt;
&lt;br /&gt;
=== Example: Similarity Search  ===&lt;br /&gt;
&lt;br /&gt;
This example shows how a text can be searched for the word &amp;quot;turnover&amp;quot; and the results formatted in bold type. A similarity search is used so that not only the word “turnover”, but also the plural form &amp;quot;turnovers&amp;quot; and declinations such as &amp;quot;turnover's&amp;quot; are found. The found expressions differ by up to two letters from the search expression:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim SearchDesc As Object&lt;br /&gt;
Dim Doc As Object&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
SearchDesc = Doc.createSearchDescriptor&lt;br /&gt;
SearchDesc.SearchString=&amp;quot;turnover&amp;quot;&lt;br /&gt;
SearchDesc.SearchSimilarity = True&lt;br /&gt;
SearchDesc.SearchSimilarityAdd = 2&lt;br /&gt;
SearchDesc.SearchSimilarityExchange = 2&lt;br /&gt;
SearchDesc.SearchSimilarityRemove = 2&lt;br /&gt;
SearchDesc.SearchSimilarityRelax = False&lt;br /&gt;
Found = Doc.findFirst (SearchDesc)&lt;br /&gt;
&lt;br /&gt;
Do Until IsNull(Found)&lt;br /&gt;
  Found.CharWeight = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
  Found = Doc.findNext( Found.End, SearchDesc)&lt;br /&gt;
Loop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|The basic idea of search and replace in {{OOo}} is comparable to that used in VBA. Both interfaces provide you with an object, through which the properties for searching and replacing can be defined. This object is then applied to the required text area in order to perform the action. Whereas the responsible auxiliary object in VBA can be reached through the Find property of the Range object, in {{OOo}} Basic it is created by the &amp;lt;tt&amp;gt;createSearchDescriptor&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;createReplaceDescriptor&amp;lt;/tt&amp;gt; call of the document object. Even the search properties and methods available differ.}}&lt;br /&gt;
&lt;br /&gt;
As in the old API from {{OOo}}, searching and replacing text in the new API is also performed using the document object. Whereas previously there was an object called &amp;lt;tt&amp;gt;SearchSettings&amp;lt;/tt&amp;gt; especially for defining the search options, in the new object searches are now performed using a &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;ReplaceDescriptor&amp;lt;/tt&amp;gt; object for automatically replacing text. These objects cover not only the options, but also the current search text and, if necessary, the associated text replacement. The descriptor objects are created using the document object, completed in accordance with the relevant requests, and then transferred back to the document object as parameters for the search methods.&lt;br /&gt;
&lt;br /&gt;
== Replacing Text Portions ==&lt;br /&gt;
&lt;br /&gt;
Just as with the search function, the replacement function from {{OOo}} is also available in {{OOo}} Basic. The two functions are handled identically. A special object which records the parameters for the process is also first needed for a replacement process. It is called a &amp;lt;tt&amp;gt;ReplaceDescriptor&amp;lt;/tt&amp;gt; and supports the &amp;lt;idl&amp;gt;com.sun.star.util.ReplaceDescriptor&amp;lt;/idl&amp;gt; service. All the properties of the &amp;lt;tt&amp;gt;SearchDescriptor&amp;lt;/tt&amp;gt; described in the previous paragraph are also supported by &amp;lt;tt&amp;gt;ReplaceDescriptor.&amp;lt;/tt&amp;gt; For example, during a replacement process, case sensitivity can also be activated and deactivated, and similarity searches can be performed. &lt;br /&gt;
&lt;br /&gt;
The following example demonstrates the use of &amp;lt;tt&amp;gt;ReplaceDescriptors&amp;lt;/tt&amp;gt; for a search within a {{OOo}} document.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim I As Long&lt;br /&gt;
Dim Doc As Object&lt;br /&gt;
Dim Replace As Object&lt;br /&gt;
Dim BritishWords(5) As String&lt;br /&gt;
Dim USWords(5) As String&lt;br /&gt;
&lt;br /&gt;
BritishWords() = Array(&amp;quot;colour&amp;quot;, &amp;quot;neighbour&amp;quot;, &amp;quot;centre&amp;quot;, &amp;quot;behaviour&amp;quot;, _&lt;br /&gt;
   &amp;quot;metre&amp;quot;, &amp;quot;through&amp;quot;)&lt;br /&gt;
USWords() = Array(&amp;quot;color&amp;quot;, &amp;quot;neighbor&amp;quot;, &amp;quot;center&amp;quot;, &amp;quot;behavior&amp;quot;, _&lt;br /&gt;
   &amp;quot;meter&amp;quot;, &amp;quot;thru&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Replace = Doc.createReplaceDescriptor&lt;br /&gt;
&lt;br /&gt;
For I = 0 To 5&lt;br /&gt;
  Replace.SearchString = BritishWords(I)&lt;br /&gt;
  Replace.ReplaceString = USWords(I)&lt;br /&gt;
  Doc.replaceAll(Replace)&lt;br /&gt;
Next I&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The expressions for searching and replacing are set using the &amp;lt;tt&amp;gt;SearchString&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ReplaceString&amp;lt;/tt&amp;gt; properties of the &amp;lt;tt&amp;gt;ReplaceDescriptors&amp;lt;/tt&amp;gt;. The actual replacement process is finally implemented using the &amp;lt;tt&amp;gt;replaceAll&amp;lt;/tt&amp;gt; method of the document object, which replaces all occurrences of the search expression. &lt;br /&gt;
&lt;br /&gt;
=== Example: searching and replacing text with regular expressions ===&lt;br /&gt;
&lt;br /&gt;
The replacement function of {{OOo}} is particularly effective when used in conjunction with regular expressions. These provide the option of defining a variable search expression with place holders and special characters rather than a fixed value. &lt;br /&gt;
&lt;br /&gt;
The regular expressions supported by {{OOo}} are described in detail in the online help section for {{OOo}}. Here are a few examples:&lt;br /&gt;
&lt;br /&gt;
* A period within a search expression stands for any character. The search expression sh.rt therefore can stand for both for &amp;lt;tt&amp;gt;shirt&amp;lt;/tt&amp;gt; and for &amp;lt;tt&amp;gt;short&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* The character ^ marks the start of a paragraph. All occurrences of the name &amp;lt;tt&amp;gt;Peter&amp;lt;/tt&amp;gt; that are at the start of a paragraph can therefore be found using the search expression &amp;lt;tt&amp;gt;^Peter&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* The character $ marks a paragraph end. All occurrences of the name &amp;lt;tt&amp;gt;Peter&amp;lt;/tt&amp;gt; that are at the end of a paragraph can therefore be found using the search expression &amp;lt;tt&amp;gt;Peter$&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* A * indicates that the preceding character may be repeated any number of times. It can be combined with the period as a place holder for any character. The &amp;lt;tt&amp;gt;temper.*e&amp;lt;/tt&amp;gt; expression, for example, can stand for the expressions &amp;lt;tt&amp;gt;temperance&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;temperature&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following example shows how all empty lines in a text document can be removed with the help of the regular expression ^$:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Dim Doc As Object&lt;br /&gt;
Dim Replace As Object&lt;br /&gt;
Dim I As Long&lt;br /&gt;
&lt;br /&gt;
Doc = ThisComponent&lt;br /&gt;
Replace = Doc.createReplaceDescriptor&lt;br /&gt;
Replace.SearchRegularExpression = True&lt;br /&gt;
Replace.SearchString = &amp;quot;^$&amp;quot;&lt;br /&gt;
Replace.ReplaceString = &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Doc.replaceAll(Replace)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>