| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, StringUtil, _crd;
- _export("StringUtil", void 0);
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "aa8435LSBtAR5HPsje6IJ2w", "StringUtil", undefined);
- /** 字符串工具 */
- _export("StringUtil", StringUtil = class StringUtil {
- /** 获取一个唯一标识的字符串 */
- static guid() {
- var guid = "";
- for (var i = 1; i <= 32; i++) {
- var n = Math.floor(Math.random() * 16.0).toString(16);
- guid += n;
- if (i == 8 || i == 12 || i == 16 || i == 20) guid += "-";
- }
- return guid;
- }
- /**
- * 转美式计数字符串
- * @param value 数字
- * @example
- * 123456789 = 123,456,789
- */
- static numberTotPermil(value) {
- return value.toLocaleString();
- }
- /**
- * 转英文单位计数
- * @param value 数字
- * @param fixed 保留小数位数
- * @example
- * 12345 = 12.35K
- */
- static numberToThousand(value, fixed) {
- if (fixed === void 0) {
- fixed = 2;
- }
- var k = 1000;
- var sizes = ['', 'K', 'M', 'G'];
- if (value < k) {
- return value.toString();
- } else {
- var i = Math.floor(Math.log(value) / Math.log(k));
- var r = value / Math.pow(k, i);
- return r.toFixed(fixed) + sizes[i];
- }
- }
- /**
- * 转中文单位计数
- * @param value 数字
- * @param fixed 保留小数位数
- * @example
- * 12345 = 1.23万
- */
- static numberToTenThousand(value, fixed) {
- if (fixed === void 0) {
- fixed = 2;
- }
- var k = 10000;
- var sizes = ['', '万', '亿', '万亿'];
- if (value < k) {
- return value.toString();
- } else {
- var i = Math.floor(Math.log(value) / Math.log(k));
- return (value / Math.pow(k, i)).toFixed(fixed) + sizes[i];
- }
- }
- /**
- * "," 分割字符串成数组
- * @param str 字符串
- */
- static stringToArray1(str) {
- if (str == "") {
- return [];
- }
- return str.split(",");
- }
- /**
- * "|" 分割字符串成数组
- * @param str 字符串
- */
- static stringToArray2(str) {
- if (str == "") {
- return [];
- }
- return str.split("|");
- }
- /**
- * ":" 分割字符串成数组
- * @param str 字符串
- */
- static stringToArray3(str) {
- if (str == "") {
- return [];
- }
- return str.split(":");
- }
- /**
- * ";" 分割字符串成数组
- * @param str 字符串
- */
- static stringToArray4(str) {
- if (str == "") {
- return [];
- }
- return str.split(";");
- }
- /**
- * 字符串截取
- * @param str 字符串
- * @param n 截取长度
- * @param showdot 是否把截取的部分用省略号代替
- */
- static sub(str, n, showdot) {
- if (showdot === void 0) {
- showdot = false;
- }
- var r = /[^\x00-\xff]/g;
- if (str.replace(r, "mm").length <= n) {
- return str;
- }
- var m = Math.floor(n / 2);
- for (var i = m; i < str.length; i++) {
- if (str.substr(0, i).replace(r, "mm").length >= n) {
- if (showdot) {
- return str.substr(0, i) + "...";
- } else {
- return str.substr(0, i);
- }
- }
- }
- return str;
- }
- /**
- * 计算字符串长度,中文算两个字节
- * @param str 字符串
- */
- static stringLen(str) {
- var realLength = 0,
- len = str.length,
- charCode = -1;
- for (var i = 0; i < len; i++) {
- charCode = str.charCodeAt(i);
- if (charCode >= 0 && charCode <= 128) realLength += 1;else realLength += 2;
- }
- return realLength;
- }
- /**
- * 是否为空
- * @param str
- */
- static IsEmpty(str) {
- return str == null || str == undefined || str.length == 0;
- }
- /**
- * 参数替换
- * @param str
- * @param rest
- *
- * @example
- *
- * var str:string = "here is some info '{0}' and {1}";
- * StringUtil.substitute(str, 15.4, true);
- *
- * "here is some info '15.4' and true"
- */
- static substitute(str) {
- if (str == null) return '';
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- rest[_key - 1] = arguments[_key];
- }
- var len = rest.length;
- var args;
- if (len == 1 && rest[0] instanceof Array) {
- args = rest[0];
- len = args.length;
- } else {
- args = rest;
- }
- for (var i = 0; i < len; i++) {
- str = str.replace(new RegExp("\\{" + i + "\\}", "g"), args[i]);
- }
- return str;
- }
- });
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=0e98aa3eea6fd9f9cde7cc7c8d25343191c17afc.js.map
|