-10

A little help please. I want to strip-off a portion of my string which is made up of a number in Java.

eg. Have the following Strings - 60067 ; 600567 and 600876 and '600676600'

How do I remove 600 from each of the strings in Java so I remain with

67 ; 567 and 876 and '676600'

2

2 Answers 2

3

As Pavneet said in his comment, this works well:

"60067".substring(3);

Also, if you want to make sure it is the string "600" that you are removing:

"60067".replaceFirst("600", "");

Java Strings have no remove method, so it's common to replace the String with a blank one, "".

Sign up to request clarification or add additional context in comments.

1 Comment

This works perfectly. Many Thanks for not shooting down my question.
0

try this:

String s = "60067 ; 600567 and 600876";
s = s.replaceAll("600", "");
System.out.println(s);

I got

67 ; 567 and 876

3 Comments

replaceAll is for regular expressions. For plain strings it is better to use replace.
He also probably doesn't want to replace all occurrences of the string, looking at his question, but seeing as he didn't explicitly specify, it's quite possible I could be wrong on that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.