4D Blog

Home Product 4D Write Pro – Find and Replace

4D Write Pro – Find and Replace

April 27, 2021

Product

For many years now, 4D Write Pro has made it possible to create simple or complex documents, either via programming using templates or by simply creating new documents from scratch. Starting with 4D v19, both developers and end users will be happy to use the new find (and replace) capabilities of 4D Write Pro. Using not just the interface… but also the code!

Let’s delve into the details!

HDI: 4D Write Pro – Find & Replace

Say hello to WP Find All

Finding (and replacing) text inside a 4D Write Pro document is already possible with basic commands like WP Get text and WP Set text. With this feature release, a new command is available that makes it possible to go faster than ever, with optional criteria!

FIND any word occurrence

Searching and replacing text in a document is a pretty typical operation and must be a simple action.

However, it’s sometimes necessary to take into account certain particularities of typography or language. For example, in Latin languages, certain letters may be capitalized or accented. You may also wish to select only whole words and not parts of words, etc. On the other hand, in Japanese, the way of writing (as well as the width of characters) has its own importance and must sometimes be taken into account or, on the contrary, ignored.

It’s also useful to specify that a search be performed either in the entire document or limited to a specific part of the document (e.g., a paragraph, section, header, footer, etc.).

All of these considerations, from the simplest to the most complex, are configurable with this new command.

Replacements and modifications

If the purpose of a search is to replace a single word (or multiple words), this can now be performed in a single operation. The replacement string just needs to be passed as a parameter to the command! The cherry on top? You can choose if the style of the characters in the replaced string should be kept or not when replacing. This can be very convenient for example if the first letter is bold, colored, or simply has a different size. For example, you can replace “Romeo” with “Juliet”   😉

If it’s not a question of modifying the content, but rather the shape of the occurrences found, just use the collection returned by the command where each element is a range. They can be used as a parameter for general 4D Write Pro functions, such as WP Set attributes.

Code sample

In the text below, we want to replace “Alpha” with “Bravo”. We don’t care about the accents and capitals, so we’ll ignore those. However, we want the typography of each letter of the original word (Alpha) to be preserved:

Before…

 

 

$find:="Alpha"
$replace:="Bravo"
$options:=wk case insensitive+wk diacritic insensitive+wk keep character style
$_ranges:=WP Find all([SAMPLE]WP; $find; $options; $replace)

…After

blank

Find more details about the command in the doc center!

4D Write Pro Interface

This new feature has been added to the 4D Write Pro Interface widgets:

Toolbar widget

blank

Side-bar widget

blank

Don’t forget, the source code is available on GitHub. Feel free to adapt it to suit your needs!

 

Discuss

Tags 4D Write Pro, Find, v19, Word processor

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

Roland Lannuzel
Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy