ToLower用法
ToLower副本用法
string testString = "This is a Test with Roman Numerals: IV, IX, XL, XC, CD, CM";
string result = testString.ToLower();
Console.WriteLine(result);// this is a test with roman numerals: iv, ix, xl, xc, cd, cm
- tolower的使用当然非常简单,但在不同平台、Linux windows mac 可能会有系统对大小写敏感不敏感的情况,
- 那么这个情况会出现在什么地方呢,就是通过
BuildPipeline.BuildAssetBundles(WindowsPlatformDirectory, assetBundleBuilds, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);(此代码为unity引擎的打包代码 会将assetBundleBuilds中的资源生成到WindowsPlatformDirectory目录下) -
AssetBundles 时,会将 AssetBundle名称中的大写字母转换为小写字母,但不会转换大写的罗马数字等特殊字符。这种行为的原因如下: 文件系统兼容性:大小写敏感性,不同的文件系统对大小写有不同的处理方式。例如,Linux 文件系统是大小写敏感的,而 Windows 文件系统默认是大小写不敏感的。为了确保跨平台兼容性,Unity 将 AssetBundle 名称统一为小写。 一致性:统一为小写可以避免因大小写不同而导致的文件冲突和加载问题。 内部处理: 哈希计算:Unity 在内部使用哈希值来标识和管理 AssetBundles。将名称转换为小写可以确保哈希值的一致性。 资源管理:统一的命名规则有助于资源管理,特别是在大型项目中,可以减少命名冲突和管理复杂性。 特殊字符处理: 保留特殊字符:大写的罗马数字等特殊字符在某些情况下具有特定含义,保留这些字符可以确保名称的语义完整性。 兼容性:某些文件系统和平台对特殊字符有特定的处理方式,保留这些字符可以避免不必要的转换和兼容性问题。~~~~
上述内容是通过通意灵码得到的答案,
ToLower示例
- 询问toLower是否会将大写罗马数字转为小写数字,ai鉴定的认为不会,
string testString = “This is a Test with Roman Numerals: IV, IX, XL, XC, CD, CM”;
string result = testString.ToLower();
Console.WriteLine(result);// this is a test with roman numerals: iv, ix, xl, xc, cd, cm
- 啪啪打脸,看来ai的水准还是有待提高~
结论
-
上述内容都不重要,情况是:
-
AssetBundles文件将字母转为小写了,但是并不会转换罗马数字,
-
需要通过路径加载AssetBundles文件,需要将路径进行ToLower进行转换 导致罗马数字也会被转为小写
-
大小写不敏感的系统还好~ 如果大小写敏感的系统 例如通过浏览器访问某个Linux服务器,来访问webgl 项目 如果服务器是大小写敏感的 就会导致使用ToLower转换的路径找不到对应的文件,
-
下面就使用ToLowerExceptRomanNumerals 来代替需要用到路径中会存在罗马数字时用ToLower的的情况
-
private static readonly Regex RomanNumeralRegex = new Regex(@"\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b", RegexOptions.Compiled); public static string ToLowerExceptRomanNumerals(this string input) { // 匹配所有的罗马数字 MatchCollection matches = RomanNumeralRegex.Matches(input); // 使用 StringBuilder 构建最终的字符串 StringBuilder sb = new StringBuilder(); int lastEndIndex = 0; foreach (Match match in matches) { // 将匹配前的部分转换为小写并添加到 StringBuilder sb.Append(input.Substring(lastEndIndex, match.Index - lastEndIndex).ToLower()); // 添加匹配到的罗马数字 sb.Append(match.Value); // 更新 lastEndIndex lastEndIndex = match.Index + match.Length; } // 将剩余部分转换为小写并添加到 StringBuilder sb.Append(input.Substring(lastEndIndex).ToLower()); return sb.ToString(); } ```


235

被折叠的 条评论
为什么被折叠?



