Skip to content
Advertisement

how do you remove a letter from a string when using substring

So I am trying to remove all the x’s from this string! Of course I can use replaceAll but I want it to remove one by one each x and then print it! But it keeps either erroring out or I just can’t seem to remove it! Of course I know how to find the x but idk how to remove afterwards!

JavaScript

Advertisement

Answer

You could work with StringBuilder, which has an inbuilt method deleteCharAt.

JavaScript

Output:

JavaScript

Explanation:

As long as the string msg still has the character to extract, a StringBuilder is made containing the current message, the first index is removed and then saved back to msg and printed.

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