在Javascript中删除字符串的第一个字符 [英] Delete first character of a string in Javascript

查看:139
本文介绍了在Javascript中删除字符串的第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果第一个字符是0,我想删除字符串的第一个字符.0可以不止一次。

I want to delete the first character of a string, if the first character is a 0. The 0 can be there more than once.

是否有一个简单的检查第一个字符并删除它的函数是否为0?

Is there a simple function that checks the first character and deletes it if it is 0?

现在,我正在尝试使用JS slice()函数但它非常笨拙。

Right now, I'm trying it with the JS slice() function but it is very awkward.

推荐答案

var s = "0000test";
while(s.charAt(0) === '0')
{
 s = s.substr(1);
}

这会杀死字符串开头的任何0。

This will kill any 0's at the start of the string.

这篇关于在Javascript中删除字符串的第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆