WP Find all
WP Find all ( targetObj ; searchValue ; searchCondition {; replaceValue} ) : Collection
Parameter | Type | Description | |
---|---|---|---|
targetObj | Object | → | Range or element or 4D Write Pro document |
searchValue | Text | → | Search value |
searchCondition | Integer | → | Search rule(s) |
replaceValue | Text | → | Replacement string |
Function result | Collection | ← | Collection of range objects |
Description
The WP Find all command searches the targetObj for the searchValue based on the searchCondition. An optional parameter can be used to replace any results found.
Note: WP Find all does not search or replace text in formulas. Use the WP Get formulas command in this case.
In the targetObj parameter, pass an object containing:
- a range, or
- an element (table / row / cell(s) / paragraph / body / header / footer / section / subsection / text box), or
- a 4D Write Pro document.
The searchValue parameter lets you pass the text to search for within the targetObj.
You can specify how the search is performed with the searchCondition parameter. You can use one (or a combination) of the following constants:
Constant | Comment |
---|---|
wk case insensitive | Strings are compared with no consideration of capitalization differences. Note that diacritical marks are taken into consideration. For example, "A" is considered the same as "a", however "a" is not considered the same as "à". |
wk diacritic insensitive | Strings are compared but the diacritical mark (e.g., accent or symbol) of letters is ignored. For example, "a" is considered the same as "à". |
wk find reverse | Search is performed in reverse order. |
wk kana insensitive | For Japanese language. Strings are compared according to the meaning (not the writing style). For example, "あ" is considered the same as "ア". When this option is set, wk width insensitive is implicit (considered set), however, the opposite is not true. |
wk keep character style | When replacing text, the existing character style is retained (if possible). |
wk override protected | Read/write protection is ignored and strings in protected areas can be replaced. |
wk use keyboard language | For string comparison, use the keyboard language property from the form object being edited instead of the current data language (default). Note: Ignored if the document is offscreen. |
wk whole word | Only strings that are complete words are considered. Matching strings within other strings are not considered. For example, "where" is not considered when found within "somewhere". |
wk width insensitive | For Japanese language. Strings are compared by character width. For example, "ア" is considered the same as "ア". |
Note: Strings are compared to the current data language unless wk use keyboard language is used.
In the optional replaceValue parameter, you can pass text to take the place of any instance of the text in searchValue found in the targetObj.
Returned Collection
The function returns a collection of range objects describing each value that was found or replaced:
- search operations - the ranges match the found strings positions
- replace operations - the ranges match the replaced strings positions
If targetObj is a range or element, found values are returned in the order they are found.
If targetObj is a 4D Write Pro document, found values are returned in the following order:
- body
- first page header for section 1 (if any)
- first page footer for section 1 (if any)
- left page header for section 1 (if any)
- left page footer for section 1 (if any)
- right page header for section (if any)
- right page footer for section 1 (if any)
- main header for section 1 (if any)
- main footer for section 1 (if any)
- repeat with section 2, section 3, and so on
- text boxes.
The order is reversed if wk find reverse is used.
An empty collection is returned if no results are found.
Example
var $userSel ;$target ;$alphaRanges : Object
var $bravoRanges:  Collection
var $options : Integer
// define search options
$options:=wk case insensitive+wk diacritic insensitive
// get current user position
$userSel:=WP Selection range(*;"WParea")
// define target
$target:=WP Get body(WParea) // search only inside the body
// launch REPLACEMENT of ALL occurences of "alpha" by "bravo" in the body
$bravoRanges:=WP Find all($target;"alpha";$options;"bravo")