I have a simple string Ex. 1.0.0.2 and I want to split and retrieve only part of the string:
output: 1.0.0 basically I want to remove all text after the third . included. I tried with split() function, count the occurrances of . and, if greater than 2, get the indexOf() third point and substring(). Is there an easier or faster method to achieve this? Maybe using regEx?
Edit:
I don’t know how many dots there will be.
If you don’t know for sure that there will be exactly three dots — so you can’t use
lastIndexOf()— then here is a regex-based solution: