-1

I have the need to to remove the initial spaces from a string of variable length, that also contains other spaces. For example (it's using extracted .mp3 metadata), the initial String is

"         My Chemical Romance" 

I'm unable to use a standard form of regex such as:

artist= artist.replace("");

As the output would become "MyChemicalRomance". Is there another way to remove the spaces at the start, especially as the String will be of variable length? Many thanks.

HamZa
  • 14,671
  • 11
  • 54
  • 75
tomandco
  • 51
  • 2
  • 10
  • use artist.trim() to remove trailing whitespace (http://stackoverflow.com/questions/9108781/how-to-remove-leading-and-trailing-whitespace-from-the-string-in-java) – Sterling Tolley Oct 27 '14 at 19:58

1 Answers1

4

Use the trim() function.

String.trim();

This will remove leading and trailing spaces.

brso05
  • 13,142
  • 2
  • 21
  • 40