---
title: "How to remove char from string"  
description: "How to remove char from string"  
author: "David Miller"  
published: 2015-02-04  
updated: 2015-02-04  
canonical: https://www.mindstick.com/forum/12940/how-to-remove-char-from-string  
category: "oops"  
tags: ["java", "array list", "string"]  
reading_time: 1 minute  

---

# How to remove char from string

I want to [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) a letter from a [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) - But only a single occurrence of the letter:

Example: if my [word](https://www.mindstick.com/forum/305/read-word-file) is "aaba" and I want to remove an 'a':

[Output](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) would be "aba" - Only the first 'a' is removed. (Not all the 'a's)

I [came up](https://answers.mindstick.com/qa/41115/who-came-up-with-the-10-percent-plan-what-did-this-plan-say) with this:

String word = "aaba"

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

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that newWord='b' [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) 'aba'

Can someone please help? For some reason I am having much difficulty with this seemingly [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) problem. What is the best way to solve this problem?

Do I need to create an [ArrayList](https://www.mindstick.com/articles/11973/arraylist-class-in-c-sharp) of some sort?

## Replies

### Reply by Anonymous User

**String replaceFirst() Method**

public String replaceFirst(String regex, String replacement)

**Parameters:**

Here is the detail of parameters:

regex -- the regular expression to which this string is to be matched.

replacement -- the string which would replace found expression.

**Code**

```
 public static void main(String[] args) {        String word = "aaba";        String newWord= word.replaceFirst("a", "");        System.out.println(newWord);    }
```

**Output**

aba


---

Original Source: https://www.mindstick.com/forum/12940/how-to-remove-char-from-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
