如果是逗号,请从字符串中删除第一个字符 [英] Remove first character from a string if it is a comma

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

问题描述

我需要在javascript中设置一个函数来删除字符串的第一个字符,但前提是它只是逗号。我找到了 substr 函数,但这将删除任何内容,无论它是什么。

I need to setup a function in javascript to remove the first character of a string but only if it is a comma ,. I've found the substr function but this will remove anything regardless of what it is.

我当前的代码是

text.value = newvalue.substr(1);


推荐答案

text.value = newvalue.replace(/^,/, '');

编辑:已测试且为真。不过,这只是一种方式。

Tested and true. This is just one way to do it, though.

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

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