gpt4 book ai didi

javascript - 将 google-app-script 中的所有拉丁字母替换为数字?

转载 作者:行者123 更新时间:2023-11-28 14:18:16 27 4
gpt4 key购买 nike

当我尝试该功能时,我尝试显示 aplhabet 中的每个字母

it outputs ("01bcdefghijklmnoprstuvwqxyz").

所以它只能变成字母“a”到数字“01”。其余字母保持不变。我试图专门针对后面的字母执行此操作,以便在执行代码时仅显示数字。

这是我尝试过的代码:

function letters_to_numbers(st)
{
a = st.replace("a", "01");
return a;
b = st.replace("b", "02");
return b;
c = st.replace("c", "03");
return c;
d = st.replace("d", "04");
return d;
e = st.replace("e", "05");
return e;
f = st.replace("f", "06");
return f;
g = st.replace("g", "07");
return g;
h = st.replace("h", "08");
return h;
i = st.replace("i", "09");
return i;
j = st.replace("j", "10");
return j;
k = st.replace("k", "11");
return k;
l = st.replace("l", "12");
return l;
m = st.replace("m", "13");
return m;
n = st.replace("n", "14");
return n;
o = st.replace("o", "15");
return o;
p = st.replace("p", "16");
return p;
r = st.replace("r", "17");
return r;
s = st.replace("s", "18");
return s;
t = st.replace("t", "19");
return r;
u = st.replace("u", "20");
return u;
v = st.replace("v", "21");
return v;
w = st.replace("w", "22");
return w;
q = st.replace("q", "23");
return q;
x = st.replace("x", "24");
return x;
y = st.replace("y", "25");
return y;
z = st.replace("z", "26");
return z;
}

最佳答案

return 语句停止函数的执行。

相反,尝试将每次代码执行的结果添加到一个空数组中,我会考虑为此循环遍历数组,而不是硬编码 26 次以上。

如果您想了解有关 return 语句的更多信息: https://www.w3schools.com/jsref/jsref_return.asp

如果您想了解有关 for 循环的更多信息: https://www.w3schools.com/js/js_loop_for.asp

关于javascript - 将 google-app-script 中的所有拉丁字母替换为数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56445238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com