programming-examples/js/String/Get a part of string after a specified character.js

13 lines
443 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function subStrAfterChars(str, char, pos)
{
if(pos=='b')
return str.substring(str.indexOf(char) + 1);
else if(pos=='a')
return str.substring(0, str.indexOf(char));
else
return str;
}
console.log(subStrAfterChars('w3resource: JavaScript Exercises', ':','a'));
console.log(subStrAfterChars('w3resource: JavaScript Exercises', 'E','b'));