Utils/StringUtils.cs

(完整代码) 1KB


using System;

namespace AppManager.Utils {
    internal static class StringUtils {
        public static string TxtEncode(string str) {
            if (!string.IsNullOrEmpty(str)) {
                str = str.Replace(Environment.NewLine, "\\r\\n").Replace("\n", "\\n").Replace("\r", "\\r");
            }
            return str;
        }

        public static string TxtDecode(string str) {
            if (!string.IsNullOrEmpty(str)) {
                str = str.Replace("\\r\\n", Environment.NewLine).Replace("\\n", "\n").Replace("\\r", "\r");
            }
            return str;
        }

        public static string Trim(string str) {
            return str.Replace("\n", "").Replace("\t", "").Replace("\r", "").Trim();
        }


        public static string FormatSize(float byteSize) {
            string unit;
            var count = byteSize;
            if (byteSize > 536870912) {
                // GB
                unit = "GB";
                count = byteSize / 1024.0F / 1024.0F / 1024.0F;
            } else if (byteSize > 524288) {
                // MB
                unit = "MB";
                count = byteSize / 1024.0F / 1024.0F;
            } else if (byteSize > 512) {
                // KB
                unit = "KB";
                count = byteSize / 1024.0F;
            } else {
                unit = "B";
            }

            return string.Format("{0:###,##0.00}" + unit, count);
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。