using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
// 将多行文字变为一行文字
// 适配 ClipboardFusion 宏脚本规范
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
// 1. 空值/空白处理:避免空输入报错
if (string.IsNullOrWhiteSpace(text))
{
return text; // 空值直接返回,不修改
}
// 2. 替换所有换行符(Windows/macOS/Linux 全兼容)
// \r\n = Windows换行 | \n = Linux/macOS | \r = 老式Mac
string singleLine = text.Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
// 3. 替换制表符为单个空格(可选,根据需求保留/删除)
singleLine = singleLine.Replace("\t", " ");
// 4. 合并多个连续空格为单个空格(避免换行替换后出现多个空格)
singleLine = Regex.Replace(singleLine, @"\s+", " ");
// 5. 去除首尾多余空格(可选,根据需求调整)
singleLine = singleLine.Trim();
// 返回处理后的单行文本
return singleLine;
}
}