Scrubbing strings in Java -


i have series of strings in following format:

string = "agregator par. l1-23 2/22.-------->efm actelis ml628  8-210  alternative 8-/208                                                        "; 

as can see, original format doesn't good, remove parts of string give following result:

"agregator par. l1-23 2/22.efm actelis ml628  8-210  alternative 8-/208" 

not of strings follow exact format, however, means they're not simple manipulate.

here's want do:

  • remove trailing blank spaces (about 56 of them, not same number)
  • remove occurrences of -------->, without removing hyphens other parts of string. number of hyphens in --------> may vary between strings

you can use regular expression remove unwanted letters.

string a= "agregator par. l1-23 2/22.-------->efm actelis ml628  8-210  alternative 8-/208                                                        ";       = a.trim().replaceall(" +", " ");      = a.replaceall("-*>", " "); 

a.trim().replaceall(" +", " ") remove spaces @ end , if more 1 spaces there replace single space.

output : "agregator par. l1-23 2/22. efm actelis ml628 8-210 alternative 8-/208"


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -