Dataview : strings manipulation — question adressed to Dataview wizards

Hi Dataview wizards !

For commodity reasons, I’m sometimes adding suffixes to the titles of my GTD notes, like this :

  • library (domain)
  • library (project)
  • library –P
  • library –K

Now, I wonder if it would be possible, in a Dataview query, to ==strip these suffixes== and get just the filenames, because when I’m listing projects or kanbans, for example, I don’t need the “–P” suffix, it slows the reading. A query sample :

TABLE
	nature,
	status
	WHERE endswith(file.name, "–P") OR 
		(contains(lower(nature), "projet")) 
SORT file.name

Thank you very much in advance !

1 Like

Hi,
If for a specific suffix, you can use the function replace() to remove the " –P".

TABLE WITHOUT ID
	link(file.name, replace(file.name, " –P", " ")) AS File,
	nature,
	status
WHERE endswith(file.name, "–P") OR 
	(contains(lower(nature), "projet")) 
SORT file.name
1 Like

Thank you very much ! What I was missing was the link function and how to use it. Now that you enlightened me, I came up with a more elaborate version that could be useful for many people :

TABLE WITHOUT ID
	link(file.name, regexreplace(file.name, "(\s–[A-Z]\s*$)|(\s\(\w+\)\s*$)", "")) AS "",
	status as "Status"
WHERE length(status)
SORT file.name
SORT status

The regular expression can strip from the end of the note name :

  • any suffix like “en dash followed by an UPERCASE character” such as –P, –D, etc.
  • OR any word in parentheses, such as (domain), (MOC), (project), etc.
    (you have to choose one of these two types of suffix; don’t use both)
  • it’s immune to extra spaces that you might have typed after the suffix but don’t see.

Enjoy !

1 Like

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