I am interested in using the String.replaceAll
function that will allow me to remove a specific sequence of a String.
Does the functionality of
String.replaceAll
replace the first occurrence of the String sequence given to, well replace? My assumption is yes.Going about replacing the particular sub-string, how would I replace the characters in the provided String?
String sentence = "@red@@blue@@green@Hello@reset@";
The substring that I want to be removed is from the
@
to the other@
, in this case, while runningString.replace
String.replaceAll("@**PATTERN HERE SO NAME WON"T MATTER**@", "");
EDIT Seeing replace and replaceAll makes since between the two differences, being one using regex. My concern is removing the first occurrence of the expression given, being the original string of
String sentence = "@red@@blue@@green@Hello@reset@";
Would have to be ran 4 times in order to have "Hello" as the remaining member of the String.
Example: Run 1 - replaceFirstOccurence("@regex@", "");
System.out.println(sentence); --> "@blue@@green@Hello@reset@"
Run 2 - replaceFirstOccurence("@regex@", "");
System.out.println(sentence); --> "@green@Hello@reset@"
Run 3 - replaceFirstOccurence("@regex@", "");
System.out.println(sentence); --> "Hello@reset@"
Run 4 - replaceFirstOccurence("@regex@", "");
System.out.println(sentence); --> "Hello"