最近用 vm C# 二次开发(多方案切换)会用到方案加载结束事件,去拿到当前加载的 sol 方案路径。vm 4.3 版本。

但将拿到的路径字节解码为字符串后,很不对劲,后面有一堆问号。于是写了一个小小的函数帮助解析出正确的方案路径。不过更简单的办法是直接调用 VmSolution.Instance.SolutionPath 就好了。


public static string GetCorrectSolPath(byte[] solPath)
{
string strangeSolPath = Encoding.UTF8.GetString(solPath);
string modifiedText = strangeSolPath.Replace("sol", "\n"); // 将 "::" 替换为换行符
string[] StrArr = modifiedText.Split(new char[] { '\n' }, StringSplitOptions.None);
return StrArr[0] + "sol";
}
–
封面来自《进击的巨人·最终季》