Reputation: 622
Hi,
I have a string of following format:
string arr = "a-b-c";
which is not constant which can be
"a-b-c-d";
I want the output as :
string result = "b-c"
or
"b-c-d-....";
I am using string.split("-")
but not sure how to skip first element.
Upvotes: 0
Views: 44
Reputation: 2211
var str = "a-b-c-d-e-f-g-h-i";
var res = str.slice(2);
alert(res) ;
Upvotes: 2
Reputation: 9571
You could use substring to skip the first two characters, then your normal `string.split("-") to get the rest into an array.
Eg:
var input = "a-b-c-d-e";
var removeFirstChar = input.substring(2);
var splitChars = removeFirstChar.split("-");
This is assuming you always want to skip the first letter and it's hyphen.
Upvotes: 0
Reputation: 18873
Use .substring()
and .indexOf()
as shown :-
var arr = "a-b-c-d";
alert(arr.substring(arr.indexOf('-') + 1));
var arr = "a-b-c-d-e-f";
alert(arr.substring(arr.indexOf('-') + 1));
Upvotes: 3