Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Whitespace concatenator

Description
Removes duplicate whitespace (double spaces, tabs, line breaks, paragraphs and mixtures thereof) AND replaces all tabs, line breaks and paragraphs with a simple whitespace.
Handy for copy-pasting from .pdfs or otherwise bad formatting to legible text.
Usage:
1. Highlight text to copy
2. Execute macro (-- text is stripped and copied to clipboard)
3. Paste wherever you want to have the text
Language
C#.net
Minimum Version
Created By
Jan Wunderlich
Contributors
-
Date Created
Feb 6, 2023
Date Last Modified
Feb 6, 2023

Macro Code

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

// The 'text' parameter will contain the text from the:
//   - Current Clipboard when run by HotKey
//   - History Item when run from the History Menu
// The returned string will be:
//   - Placed directly on the Clipboard
//   - Ignored by ClipboardFusion if it is 'null'
public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
    {
	// Copy the selected text
	text = BFS.Clipboard.CopyText();
		
	// Remove whitespace
        StringBuilder a = new StringBuilder(text.Length);
		for(int i = 0; i < text.Length -1; ++i)
		{
            char c = text[i];
			char d = text[i+1];
            if ((c == ' ' || c == '\t' || c == '\n' || c == '\r') && (d == ' ' || d == '\t' || d == '\n' || d == '\r'))
            {
                continue;
            }
			else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
			{
				a.Append(' ');
				continue;
			}
            a.Append(c);
        }
		//BFS.Clipboard.PasteText(a.ToString());
		BFS.ClipboardFusion.AddHistoryText(a.ToString());
        return a.ToString();   
    }
}