Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:27:02+00:00 2026-06-10T02:27:02+00:00

I have a string like : string = abcdefghabcd Now lets say I want

  • 0

I have a string like :

string = abcdefghabcd

Now lets say I want to replace the first occurrence of a. I tried something like this :

string[string.indexOf('a')] = '0'

But this doesn’t seems to be working. Any other way I can do this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:27:04+00:00Added an answer on June 10, 2026 at 2:27 am

    In Java you can use String.replaceFirst() :

    String s = "abcdefghabcd";
    s = s.replaceFirst("a", "0");
    System.out.println(s);
    

    Output will be :

    0bcdefghabcd
    

    Warning : the replaceFirst() method takes a regex : so if you want to replace a special character like [ you need to escape by putting a \ before it. \ being a special character itself, you need to double it as follow :

    s = s.replaceFirst("\\[", "0");
    

    Here is the documentation on Java Regular Expressions. Also, here is Oracle’s Java tutorial on manipulating Characters in Strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have string like this: String q = foo (one) bla (two)
I have string like First Last Name I want to replace empty spaces to
suppose I have string like this str1ng for test now i want to check
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have string like this 0100110011001 I want to convert it to byte array
I have string like order by o desc,b asc Here I want to replace
I have string like this first#second, and I wonder how to get second part
I have string like this: Mon, 14 May 2012 13:56:38 GMT Now I just
I have string like this: $string = a + b + c; . Now
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.