Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Paste clipboard text in quotes

Description
This macro will wrap the text that's currently on the clipboard in quotes and then paste it.
Language
C#.net
Minimum Version
Created By
DetlefS
Contributors
-
Date Created
Feb 15, 2023
Date Last Modified
Feb 15, 2023

Macro Code

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

// Macro checks if the clipboard contains text, then checks if the text
// contains whitespaces, then checks if no quotes are around text.
// If all conditions are fullfilled, it pastes the text surrounded
// by quotes (") into the active window.
//
// Notes: The clipboard is not changed. Existing quotes withing the text
// are not escaped.
public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
		if (BFS.Clipboard.HasText())
		{
			var rex = new Regex(@"\s");
			if (rex.IsMatch(text))
			{
				string qtext = string.Empty;
				if (!(text.StartsWith("\"") && text.EndsWith("\"")))
				{
					qtext = "\"" + text + "\"";
				}
				BFS.Clipboard.PasteText(qtext);
			}
		}
		return text;
	}
}