我有一个字符串12345.00,我希望它返回12345.0。
我看了一下trim,但它看起来只是在修剪空白和切片,我不知道这是如何工作的。有什么建议吗?
我有一个字符串12345.00,我希望它返回12345.0。
我看了一下trim,但它看起来只是在修剪空白和切片,我不知道这是如何工作的。有什么建议吗?
当前回答
使用正则表达式:
设aStr=“12345.00”;aStr=aStr替换(/.$/,'');控制台日志(aStr);
其他回答
使用正则表达式:
设aStr=“12345.00”;aStr=aStr替换(/.$/,'');控制台日志(aStr);
使用子字符串获取_bar左侧的所有内容。但首先必须在字符串中获取_bar的instr:
str.substring(3, 7);
3是起点,7是长度。
debris = string.split("_") //explode string into array of strings indexed by "_"
debris.pop(); //pop last element off the array (which you didn't want)
result = debris.join("_"); //fuse the remainng items together like the sun
试试看:
const myString=“Hello World!”;console.log(myString.slice(0,-1));
你可以用切片!你只需要确保你知道如何使用它。正数是相对于开头的,负数是相对于结尾的。
js>"12345.00".slice(0,-1)
12345.0