0) { var valueLen = value.length; if (Array.isArray(group) && group.length > 0) { group = grou_c#split()分组后变为单个字符如何重新组为字">
当前位置:   article > 正文

字符串分割重组字符串方法_c#split()分组后变为单个字符如何重新组为字符串

c#split()分组后变为单个字符如何重新组为字符串

实现代码

function RegroupStr(group, value, splitstr, maxlen) {
    if (typeof value == "string" && value.length > 0) {
        var valueLen = value.length;
        if (Array.isArray(group) && group.length > 0) {
            group = group.sort(function (a, b) {
                return a - b;
            }).filter((x) => { if (typeof x == "number" && x > 0 && x % 1 === 0) { return x } });
            var strsplit = "-";
            var newValue = "";
            if (splitstr != undefined&& typeof splitstr === "string") {
                strsplit = splitstr;
            }
            if (group.length > 0) {
                if (typeof splitstr == "number") {
                    strsplit = "-";
                    valueLen = splitstr;
                }
                if (maxlen && typeof maxlen == "number") {
                    valueLen = maxlen;
                }
                if (group.indexOf(valueLen) == -1 && group[group.length - 1] < valueLen) {
                    group.push(valueLen);
                }
                group = Array.from(new Set(group));
                $.each(group, function (i, _i) {
                    if (i != 0) { i = group[i - 1]; }
                    newValue += value.substring(i, _i) + strsplit;
                })
                while (newValue.substring(newValue.length - 1, newValue.length) == strsplit) {
                    newValue = newValue.substring(0, newValue.length - 1);
                }
                return newValue;
            }
        }
    }
    return "";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

调用方式

在这里插入图片描述

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/89925
推荐阅读
相关标签
  

闽ICP备14008679号