I have a dynamic string value which includes language and country code. I need to extract the value before hyphen and store it in a variable. How can I do this? I don't know how many characters will be there before the hyphen. I cannot use substring(). Note: I know how to extract after hyphen using split(). I need to get before value.
mystr = "eng-can"; Output: extactedstr = "eng"
https://stackoverflow.com/questions/66609111/get-everything-in-a-string-before-hyphen-in-javascript March 13, 2021 at 08:59AM
没有评论:
发表评论