forum

Home / DeveloperSection / Forums / How to remove char from string

How to remove char from string

David Miller 2272 04-Feb-2015

I want to remove a letter from a String - But only a single occurrence of the letter:

Example: if my word is "aaba" and I want to remove an 'a':

Output would be "aba" - Only the first 'a' is removed. (Not all the 'a's)

I came up with this:

String word = "aaba"

String newWord = word.replace(a, "");

The problem is that newWord='b' instead of 'aba'

Can someone please help? For some reason I am having much difficulty with this seemingly simple problem. What is the best way to solve this problem?

Do I need to create an ArrayList of some sort?


Updated on 04-Feb-2015

Can you answer this question?


Answer

1 Answers

Liked By