Using Dataview Replace function to change/hide text/strings

What I’m trying to do

I’d like to replace text in tasks and tables that is repeated. I use this naming convention for some ordered notes that I want in a specific order in the folder. I then use Folder Notes for MOCs and then use Dataview to construct those. But when I make a table/list I don’t need that structured bit of the file name.

Yes, I am aware of properties and no they are not a suitable replacement, please don’t suggest using those instead.

Dataview seems to have a function for replacing strings, but I cannot for the life of me figure out where it should actually go.

Things I have tried

So I have a

``` dataview
TABLE WITHOUT ID file.link AS Notes, date AS "Date"
FROM #Notes 
WHERE contains(file.folder, this.file.folder)
SORT file.name ASC

And I want to replace the string SD2.0 with nothing. This appears like it should do that:

replace("SD2.0","")

But I cannot figure out where to put it. I don’t know if I’ve constructed it wrong or what.

Secondly, I need this replacement to only occur after the sorting to ensure the order is maintained. Which would be more of a concern if I could make it work at all!

Hi!

replace() takes three arguments:

  1. original string
  2. part to replace
  3. replacement

You want to replace a part of the link, if I understood you correctly. That is not possible, because replace() expects strings for each argument. You could however replace a part of the file.name:

replace(file.name, "SD2.0", "")

Place this in a link()-function to get clickable links back in your data view-result:

link(file.name, replace(file.name, "SD2.0", ""))

Your full query would be:

TABLE WITHOUT ID link(file.name, replace(file.name, "SD2.0", "") AS Notes, date AS "Date"
FROM #Notes 
WHERE contains(file.folder, this.file.folder)
SORT file.name ASC

Your desired sort-order isn’t affected, because SORT uses the origin file.name.

1 Like

Amazing, thank you so much! It was just the string that represented the name that I wanted replaced, not to change the link itself, so your solution is precisely what I wanted.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.