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.

Manipulating a string of comma separated words

Featured Replies

Hello all,

I have been pondering this scenario for a while, but I inevitably end up with multiple commas or removing data that should not be removed, so I am asking for your help. :

I have a field, Tags, which contains words or sentences that have been added to the record. "Tags" could look like this:

,Red,Apple,Tastes sweet

Now, I have a second field, "Add/Remove", that allows the user to add a tag to the record. Now, if I enter "Round" and presses a button, then the word "Round" is added to the string, along with an leading comma, so the string now reads:

,Red,Apple,Tastes sweet,Round

The script to do this contains a single "Set field" command with this calculation:

Tags & "," & Add_Remove

This works fine. Now comes the challenge. Lets say I want to remove the word Apple? I have done this so far:

If a button is clicked then the script "Remove" is called. It contains a single "Set field" command with this calc:

Substitute ( Tags; "," & Add_Remove ; "" )

This works fine as long as Apple does not exist twice in the string. If the Tags line was:

,Red,Apple,Apples tastes sweet,Round

then the resulting Tags field would read:

,Reds tastes sweet,Round

And that is not really what I want. :

I have tried adding a comma to what is inserted, so there will always be a comma at the end of the word, but then the second word inserted will start with ",," which I do not want. Also I would really like to be able to have a string nicely formatted, so the initial leading comma and an eventual trailing comma in the entire string gets stripped, to read:

Red,Apple,Apples tastes sweet,Round

instead of:

,Red,Apple,Apples tastes sweet,Round,

Hope someone can help. :)

Edited by Guest

First, I would suggest you use a return-separated list, since this is a format that Filemaker understands and there are several functions to deal specifically with such lists.

To answer your question: to remove the value "Apple" from ",Red,Apple,Apples tastes sweet,Round":


Substitute ( Tags & ",§" ; [ "," & Add_Remove & "," ; "," ] ; [",§" ; "" ] )

  • Author

Thank you comment. How would I go about creating this scenario using a return separated list?

About the same way - except it would be more convenient to keep a trailing separator instead of a leading one (if at all).

  • Author

Yeah, but how do I get the formula right then? How do I describe the line break as seperator? n ?

  • Author

So would this be right:

Substitute ( Tags ; [ "¶" & Add_Remove & "¶" ; "¶" ] ; ["¶§" ; "" ] )

or am I missing the point?

To remove:


Substitute ( "§¶" & Tags ; [ ¶ & Add_Remove & ¶ ; ¶ ] ; [ "§¶" ; "" ] )





or:





FilterValues ( Tags ; Substitute ( ¶ & Tags & ¶ ; ¶ & Add_Remove & ¶ ; ¶ ) )









To add:





Tags & Add_Remove & ¶

  • Author

Thank you very much for all your help.

What does the paragrah sign (§) mean?

It's just a marker, assumed not to appear anywhere in your "real' text. I use it to mark the added leading separator, so that it can be removed at the end without affecting the rest of the list.

  • Author

Hmmm....this piece of content:

Anders Sørensen

Gør dette

Hudelihut

Svend

Hudelihut2

Dette er en test

Dette er også en test

Anders Svendsen

Is converted to:

Anders SørensenGør detteHudelihutHudelihut2Dette er en testDette er også en testAnders Svendsen

if I try to remove "Svend" using the formula:

Substitute ( "¶" & test_val::Tags ; [ ¶ & test_val::Insert & ¶ ; ¶ ] ; [ "¶" ; "" ] )

What am I missing?

What do you mean "what am I missing"? You are missing the part you have removed. The part that you asked about, and were told that it guards against removing ALL returns in the final substitution.

  • Author

Oh, I am sorry. I must have misunderstood your explanation earlier. I understood your sentence "It's just a marker, assumed not to appear anywhere in your "real' text" as if it was just something you used to point something out in your example, and that it was not supposed to appear in my formular. I am sorry that i misunderstood, but I am not a native of your tongue nor of FileMakers scripting language. If only FileMaker understood the Linux 'sed' command. :

Well, I think I understand now. Thank you for pointing out my mishap so clearly.

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.