I have a series of strings in the following format:
String a = "Agregator par. L1-23 2/22.-------->EFM Actelis ML628 8-210 alternative 8-/208 ";
As you can see, the original format doesn’t look very good, so I would like to remove parts of the string to give the following result:
"Agregator par. L1-23 2/22.EFM Actelis ML628 8-210 alternative 8-/208"
Not all of my strings follow this exact format, however, which means they’re not simple to manipulate.
Here’s what I want to do:
- Remove all trailing blank spaces (about 56 of them, but not always the same number)
- Remove all occurrences of
-------->, without removing hyphens from other parts of the string. The number of hyphens in-------->may vary between strings
You can use regular expression to remove unwanted letters.
a.trim().replaceAll(" +", " ")will remove all spaces at end and if more than one spaces are there it will replace by single space.Output :
"Agregator par. L1-23 2/22. EFM Actelis ML628 8-210 alternative 8-/208"