I need to take a String
and deleting all the regexes in it starting with character
'[' and ending with character
']'.
Now i don't know how to tackle this problem. I tried to convert the String
to character array and then putting empty characters from any starting '[' till his closing ']' and then convert it back to a String
using toString()
method.
MyCode:
char[] lyricsArray = lyricsParagraphElements.get(1).text().toCharArray();
for (int i = 0;i < lyricsArray.length;i++)
{
if (lyricsArray[i] == '[')
{
lyricsArray[i] = ' ';
for (int j = i + 1;j < lyricsArray.length;j++)
{
if (lyricsArray[j] == ']')
{
lyricsArray[j] = ' ';
i = j + 1;
break;
}
lyricsArray[j] = ' ';
}
}
}
String songLyrics = lyricsArray.toString();
System.out.println(songLyrics);
But in the print line of songLyrics i get weird stuff like
[C@71bc1ae4
[C@6ed3ef1
[C@2437c6dc
[C@1f89ab83
[C@e73f9ac
[C@61064425
[C@7b1d7fff
[C@299a06ac
[C@383534aa
[C@6bc168e5
I guess there is a simple method for it. Any help will be very appreciated.
For clarification:
converting "abcd[dsadsadsa]efg[adf%@1]d"
Into "abcdefgd"