From c65c35e26d3c8e641c194c513dae2fc73fd608e9 Mon Sep 17 00:00:00 2001 From: Oliver Wong Date: Tue, 10 Mar 2026 15:41:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=81=97=E6=BC=8F=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExcelTool/StringExtensions.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ExcelTool/StringExtensions.cs diff --git a/ExcelTool/StringExtensions.cs b/ExcelTool/StringExtensions.cs new file mode 100644 index 0000000..b2303b4 --- /dev/null +++ b/ExcelTool/StringExtensions.cs @@ -0,0 +1,32 @@ +using System.Globalization; + +namespace ExcelTool; + +public static class StringExtensions +{ + /// + /// 将 PascalCase 字符串转换为 camelCase + /// + public static string ToCamelCase(this string input) + { + if (string.IsNullOrEmpty(input)) + { + return input; + } + + // 如果第一个字符已经是小写,或者不是字母,直接返回(避免不必要的操作) + if (!char.IsUpper(input[0])) + { + return input; + } + + // 特殊情况:如果字符串只有一个字符且是大写,直接转小写 + if (input.Length == 1) + { + return input; + } + + // 将第一个字符转小写,拼接剩余部分 + return char.ToLower(input[0], CultureInfo.InvariantCulture) + input.Substring(1); + } +} \ No newline at end of file