Skip to content
Advertisement

How to remove a certain number of characters at the start of a string

I have a dataset of NHL Free Agents, however they are numbered as a part of the name. I am trying to make “1. Alex Ovechkin” look like “Alex Ovechkin”. Basically just trying to delete the number, period, and space between.

Dataset shown here

I have used the following code to successfully delete the numbers for the first 10 entries, however at entry 11 I need to delete 4 characters instead of 3. The same goes for row 100, I need to delete 5 characters to delete the numbers, period, and space.

This is the code that I have been trying to use to know avail.

JavaScript

This works for the first 10 entries, but after that there is a space from 11-100, and a period and a space for the rest.

I also tried the following code, which worked for the first 10, but deleted the rest of the entries.

JavaScript

My last attempt was to make a for loop, but did not work.

JavaScript

I’ve ran out of ideas to try, and would love some help in finding the most efficient way to do this. Thanks so much!

Advertisement

Answer

split by . and get string index 1 of the output

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement