I am playing with some code to manipulate MP3 ID3 tags, and have come across a strange problem.
To get you up to speed, ID3 (v1) supports a number of informational fields, usually 30 bytes long. If a field, such as artist-name, does not require all 30 bytes, any unused bytes will be written as \u0000 (its unicode representation)
Using the following code, I am able to read an appropriate piece of file using a RandomAccessFile Object, but the app hangs on the trim() method. Without calling trim(), the code runs fine, but I get a load of garbage, which is the \u0000 bytes.
Using yeilds the same problem.
Is there any preferred method of overcomming this pitfall? I am sure I am not the first programmer to handle c-strings before
Jon Bates [ October 06, 2005: Message edited by: Jon Bates ]
The String class has a constructor that lets you specify an offset and count into the byte array. Simply scan the byte array for the zero, and only specify the byte array up to the zero. (The offset should be zero. You only want to vary the count)