• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

C-String woes (\0)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All.

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

Regards,

Jon Bates
[ October 06, 2005: Message edited by: Jon Bates ]
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

Henry
 
Jon Bates
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers

I was doing a little late night hacking last night, and it turned out that the trim function worked fine. I was actually going into an infinite loop farther down :S

Jon Bates
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic