DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Creating Aliases With Optional Parameters  (Read 11,659 times)

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Creating Aliases With Optional Parameters
« on: August 05, 2015, 08:33 PM »
So, I've just gotten into creating aliases, and I don't know how I didn't do this before!  But I want to create an alias with optional parameters, and regex is not working for me.

The program (QuickNote for OneNote - note.exe) allows you to feed in the note text, a switch for displaying the note, and a switch for the category.  I want the switch for the category to be optional.

The RegEx

^QuickNote (.*),(.*)?

The commands:

QuickNote - $$1 | C:\Users\wraith808\My Files\Dropbox\Tools\QuickNote\Note.exe $$1 /sect $$2
QuickNote and Display - $$1 | C:\Users\wraith808\My Files\Dropbox\Tools\QuickNote\Note.exe $$1 /disp /sect $$2

It works... but you have to put a , at the end (I tried making the , optional, but that made it match the whole string, instead of splitting it).  I can live with that, even though it's suboptimal.

Is there a way to make it, however, so that if the second param is empty, it uses a default for that second parameter?  Or to check if that second parameter is set, and change behavior based on that?
« Last Edit: September 15, 2015, 06:30 PM by wraith808 »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Creating Aliases With Optional Parameters
« Reply #1 on: August 06, 2015, 05:11 AM »
quick response first: perhaps the easiest solution would be to create 2 aliases, one for when you have both parameters and one for if you have only one.
there are probably other solutions using regex, though i dont know off hand of a way to have a default parameter.. it's an interesting idea for a feature to add to the alias system..

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 11,205
    • Participated in NANY Challenge Fourteen Times
    • Coding Snacks
    • Writer
    • Hardware Hacker
Re: Creating Aliases With Optional Parameters
« Reply #2 on: August 06, 2015, 02:03 PM »
quick response first: perhaps the easiest solution would be to create 2 aliases, one for when you have both parameters and one for if you have only one.
there are probably other solutions using regex, though i dont know off hand of a way to have a default parameter.. it's an interesting idea for a feature to add to the alias system..

That's what I thought the answer would be after playing with it a bit.  Thanks for the reply.

Original address: https://www.donationcoder.com/forum/index.php?topic=41392.0