如何从此字符串中删除前5个字符?
我有一个类似的字符串(HTML选择列表):
const config = {
"celsius": {
"celsius": v => v,
"fahrenheit": v => v * 1.8 + 32,
"kelvin": v => v + 273.15,
"rankine": v => (v + 273.15) * 1.8,
"reaumur": v => v * 0.8,
},
// more...
}
我想
var listOperation = config[listFromV][listToV].substring(5);
document.getElementById("operationPlace").innerHTML = listOperation;
// now it looks like this: v => v or v => v * 1.8 + 32 etc.
// should look like this: v or v * 1.8 + 32 etc. (I'd like to change that "v" to numbers from the input (inputPlace) too)
从尝试使用substring的输出(操作场所)中剪切前5个字符,但它不起作用。有办法这样做吗?
I have a string like this (HTML select list):
const config = {
"celsius": {
"celsius": v => v,
"fahrenheit": v => v * 1.8 + 32,
"kelvin": v => v + 273.15,
"rankine": v => (v + 273.15) * 1.8,
"reaumur": v => v * 0.8,
},
// more...
}
And I want to cut the first 5 characters from the output (operationPlace)
var listOperation = config[listFromV][listToV].substring(5);
document.getElementById("operationPlace").innerHTML = listOperation;
// now it looks like this: v => v or v => v * 1.8 + 32 etc.
// should look like this: v or v * 1.8 + 32 etc. (I'd like to change that "v" to numbers from the input (inputPlace) too)
I tried using substring, but it didn't work. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在其上调用
.toString
来获取字符串形式的函数的定义,然后调用.substring
以摆脱功能签名部分:请注意这是幼稚的方法,只能适用于签名的签名,由单个1个字符的长论点和箭头符号组成,而没有括号。
You can obtain the definition of a function in the form of a string by calling
.toString
on it, then call.substring
to get rid of the function signature part:Note that this is approach is naive and will only work for functions whose signature is composed of a single 1-character long argument and arrow notation without parenthesis.