You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何升级Adobe Increment Stamp代码实现字母+数字格式递增?

自定义Adobe增量印章升级:支持字母+数字组合递增

我现有一款自定义Adobe增量印章,可实现数字(如1、2、3)或单个字母(如A、B、C)的递增。现希望升级该印章的代码,使其支持字母+数字组合格式(如A1、A2、A3或B1、B2、B3)的递增,当前使用的代码如下:

if (event.source.forReal && event.source.stampName == "#qT1ZWzIPGprVS_jnLHz-tB")
    {
        if ("aincState" in event.source.source.info)
            {
                if (!isNaN(event.source.source.info.aincState))
                    {
                        event.source.source.info.aincState = String(Number(event.source.source.info.aincState)+1);
                    }
                else if (event.source.source.info.aincState.length == 1)
                    {
                        var ascii = event.source.source.info.aincState.charCodeAt(0);
                        if ((ascii >= 65 && ascii < 90) || (ascii >= 97 && ascii < 122))
                            {
                                event.source.source.info.aincState = String.fromCharCode(ascii+1)
                            }
                        else if (ascii == 122)
                            {
                                event.source.source.info.aincState = "a";
                            } 
                        else
                            event.source.source.info.aincState = "A";
                    }
                else
                    {
                        event.source.source.info.aincState = "A";
                    }
            }
        else
        {
            event.source.source.info.aincState = app.response("Enter number or letter:", "Initialize State");
        }
    event.value = event.source.source.info.aincState;
}

修改后的完整代码

if (event.source.forReal && event.source.stampName == "#qT1ZWzIPGprVS_jnLHz-tB") {
    if ("aincState" in event.source.source.info) {
        const currentState = event.source.source.info.aincState;
        // 匹配字母+数字组合格式(支持多字母、多数字,如AB12、c3)
        const comboMatch = currentState.match(/^([A-Za-z]+)(\d+)$/);
        
        if (comboMatch) {
            // 拆分字母前缀和数字后缀
            const letterPart = comboMatch[1];
            const numberPart = parseInt(comboMatch[2], 10);
            // 数字递增,字母保持原格式不变
            event.source.source.info.aincState = letterPart + (numberPart + 1);
        } else if (!isNaN(currentState)) {
            // 保留原有纯数字递增逻辑
            event.source.source.info.aincState = String(Number(currentState) + 1);
        } else if (currentState.length == 1) {
            // 保留原有纯字母递增逻辑
            const ascii = currentState.charCodeAt(0);
            if ((ascii >= 65 && ascii < 90) || (ascii >= 97 && ascii < 122)) {
                event.source.source.info.aincState = String.fromCharCode(ascii + 1);
            } else if (ascii == 122) {
                event.source.source.info.aincState = "a";
            } else {
                event.source.source.info.aincState = "A";
            }
        } else {
            // 非法格式默认重置为A1
            event.source.source.info.aincState = "A1";
        }
    } else {
        // 更新初始化提示,明确支持的输入格式
        event.source.source.info.aincState = app.response("Enter number, letter, or combo (e.g., A1, b2):", "Initialize State", "A1");
    }
    event.value = event.source.source.info.aincState;
}

关键修改说明

  • 新增组合格式解析:通过正则表达式/^([A-Za-z]+)(\d+)$/识别字母+数字组合,拆分前缀字母和后缀数字,支持多字母(如AB1→AB2)、多数字(如C10→C11)场景
  • 组合格式递增逻辑:保持字母部分不变,仅对数字部分执行加1操作,符合常规递增需求
  • 兼容原有功能:完整保留纯数字、纯字母的递增逻辑,确保原有使用场景不受影响
  • 优化初始化引导:更新输入提示文本并设置默认值A1,明确告知用户支持的输入格式

内容的提问来源于stack exchange,提问作者Ari Perez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 16:21:01