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

  • SEARCH
  • Home
  • 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 365351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:31:44+00:00 2026-05-12T13:31:44+00:00

So, i have some String with digits and another symbols, and i want to

  • 0

So, i have some String with digits and another symbols, and i want to increment the value of each digit at 1. For example: “test1check2” from this String i want to recieve “test2check3”. And can i make this only with method “replaceAll”? (i.replaceAll(“\d”, …) something like that)?, without to use methods such like indexOf, charAt…

  • 1 1 Answer
  • 1 View
  • 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-05-12T13:31:44+00:00Added an answer on May 12, 2026 at 1:31 pm

    I don’t think you can do it with a simple replaceAll(…), you’ll have to write a few lines like:

    Pattern digitPattern = Pattern.compile("(\\d)"); // EDIT: Increment each digit.
    
    Matcher matcher = digitPattern.matcher("test1check2");
    StringBuffer result = new StringBuffer();
    while (matcher.find())
    {
        matcher.appendReplacement(result, String.valueOf(Integer.parseInt(matcher.group(1)) + 1));
    }
    matcher.appendTail(result);
    return result.toString();
    

    There’s probably some syntax errors here, but it will work something like that.

    EDIT: You commented that each digit must be incremented separately (abc12d -> abc23d) so the pattern should be changed from (\\d+) to (\\d)

    EDIT 2: Change StringBuilder to StringBuffer as required by Matcher class.

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

Sidebar

Related Questions

HI, I have some string from XML file, and I I want to replace
I have some String[] arrays, for example: ['a1', 'a2'] ['b1', 'b2', 'b3', 'b4'] ['c1']
I have some string like this: 04:51 05:09 05:29_ 05:49 06:09 06:29 06:49_ 07:09
I have some random string, let's say : s = This string has some
I have some problem to get the utf-8 string from PHP using jQuery $.load()
I have some html extracted to a string var, and want to then use
Not sure if this is the best approach but I have some string which
I have some float values I want to convert to a string, I want
I have a string with digits like so - digit = 7316717 Now I
Trying to efficiently extract some numbers from a string and have tried java.util.regex.Matcher com.google.common.base.Splitter

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.