从字符串中删除前导逗号 [英] Remove leading comma from a string

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

问题描述

我有以下字符串:

",'first string','more','even more'"

我想将其转换为数组但显然由于第一个逗号而无效。如何从字符串中删除第一个逗号并使其成为有效的数组?

I want to transform this into an Array but obviously this is not valid due to the first comma. How can I remove the first comma from my string and make it a valid Array?

我想最终得到这样的结果:

I’d like to end up with something like this:

myArray  = ['first string','more','even more']


推荐答案

删除您要使用的第一个字符:

To remove the first character you would use:

var myOriginalString = ",'first string','more','even more'"; 
var myString = myOriginalString.substring(1);

我不确定这会是你想要的结果,因为你仍然需要拆分它以创建一个数组。可能类似于:

I'm not sure this will be the result you're looking for though because you will still need to split it to create an array with it. Maybe something like:

var myString = myOriginalString.substring(1);
var myArray = myString.split(',');

请记住,'字符将是此处拆分中每个字符串的一部分。

Keep in mind, the ' character will be a part of each string in the split here.

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

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