Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Replace 1- 2- and 3-letter words in a Text Field

Featured Replies

Hi,

I have the following script which is supposed to create a keyword list from a long text field. Where it is failing is that certain times either a letter or series of letters, not only comes up to be replaced in the text, but also comes at the end of other words in the text. For instance, I have the script replace the word "MB ", but then when "dumb " appears, it becomes "du". Eventually, if the text is long enough, it all starts to deteriorate, since then "du" is a two-letter word to be deleted, and so on, until there's little but garbage left, not keywords. Here's the script:

Go to Record/Request/Page [ First ]

Loop

Set Field [ CommonWords_Holder, CommonWords2 ] (This sets a global to the text field contents)

Loop

Exit Loop If [ WordCount(CommonWords_Holder) ? 1 ]

Set Field [ CommonWords_Holder, Trim(CommonWords_Holder) ]

Copy [ Word_Copy ] [ Select entire contents ] (this retrieves the first word of the text from a calc field which holds it)

Paste [ Global_Text_Holder ] [ Select entire contents ] (This is a text global for holding the first word)

Go to Field [ CommonWords_Holder ] [ Select/perform ]

Perform Find/Replace [ Find: Global_Text_Holder_Calc; Replace:

Try replacing based on " " & Global_Text_Holder & " ". This ensures that ' dumb ' is left alone while ' mb ' is removed.

  • Author

Hi--

Actually, the reason I didn't do that is it creates another bug. When a word is first in the list, normally, there is no space in front of it. So if the word is "Foo ", It will never be replaced, and so the script keeps printing "Foo " endlessly in the keywords field. So the problem is that I don't know how to account for both instances.

All My Best,

Jeffrey

If CommonWords_Holder is the field containing the text, simply prepend/append a " " wherever you require it. E.g. Set Field[ CommonWords_Holder, " " & Trim(CommonWords_Holder) & " "].

Will that work for you?

So add a space to the list before you start replacing, and remove it at the end.

  • Author

Looks like that's working great!

Thanks!

All My Best,

Jeffrey

Here is an alternative way that is a bit more efficent

1. Create a global number field

g_WordCount

2. Change your CommonWords_Holder to a text field.

3. Create a 1 to 1 self relationship (UniqueID::UniqueID)

4. Create a value list "Keywords" that uses values from related field selfjoin::CommonWords_Holder

Your Script would be:

set field [g_WordCount, wordcount(CommonWords2)]

loop

if [length(leftwords(rightwords(CommonWords2,g_WordCount),1))>3]

set field [CommonWords_Holder,CommonWords_Holder& Leftwords(Rightwords(CommonWords2,g_WordCount),1)& "PP"]

end if

set field [g_WordCount, g_Wordcount-1]

exit loop if [g_wordcount=0]

end loop

set field [CommonWords_Holder, ValueListItems(status(currentFileName, "KeyWords"))

This adds every word larger than 3 letters to WordCount_Holder seperated by carrige returns, then uses the valuelistitems function to filter out duplicates and alphabetize. Just tested it out- works great. I hope that is what you wanted...Anyway, had some time to kill.

-Raz

I wish I had time like that. laugh.gif

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.