0

I am storing below number as a string. How can I remove the first three characters & last one character from the string?

String No = "00098000002208";
2
  • 8
    What have you tried? See the substring method of String class. Commented May 9, 2019 at 4:43
  • Is the format of string going to remain same always? Commented May 9, 2019 at 5:09

1 Answer 1

4

The easiest and probably fastest way would be to just use the base string function substring:

String input = "00034000004409";
String output = input.substring(3, input.length()-1);

We could also try doing a regex replacement:

String output = input.replaceAll("^.{3}(.*).$", "$1");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.