473,378 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Very strange string problem using ASCIIEncoding

wk
Hi,
I am reading a mp3 file's last 128 bytes and putting the text into
string variables.
What is happening is that the string is being stored with, probably
some wrong encoding or character, and hence has a " in front, and i
cant see the full string in VB 2005 express's debug mode. I have based
this off an example from the web.

I have spent a full day trying to debug this with a lot of different
ways, and now am exausted with ideas.

try giving the code any mp3 file on your disk, and then debug at line
75 of class1.vb to see the value of 'Title' variable.
Here is the code. When u run it, becuase of the problem said above, u
wont see the "<" in the messagebox

uage from form1.vb
----------------------------------
Dim mp3 As New ID3v1()
mp3.filename = "c:\temp\GarajBarasSawanGhirAayo-junoon.mp3"
mp3.filename = "c:\temp\BullaKiJana.mp3"
mp3.Read()
MsgBox(mp3.Artist.Trim & "<")
class1.vb
-----------------
Imports System
Imports System.IO
Imports System.Text

'/ <summary>
'/ Reads/writes Id3v1 tags. lots of help from Paul Lockwood's code
'/ http:'www.csharphelp.com/archives/archive226.html
'/ </summary>
Public Class ID3v1

Public filename As String

Public Title As String
Public Artist As String
Public Album As String
Public Year As String
Public Comment As String
Public GenreID As Integer
Public Track As Integer

Public hasTag As Boolean

Private Sub Initialize_Components()

hasTag = False
filename = ""
Title = ""
Artist = ""
Album = ""
Year = ""
Comment = ""

GenreID = 0
Track = 0
End Sub
Public Sub ID3v1()

Initialize_Components()
End Sub

Public Sub ID3v1(ByVal fname As String)

Initialize_Components()
filename = fname
End Sub
Public Sub Read()

' Read the 128 byte ID3 tag into a byte array
Dim oFileStream As FileStream = New FileStream(filename,
FileMode.Open)
'oFileStream = New FileStream(filename, FileMode.Open)
'byte[] bBuffer = new byte[128]
Dim bBuffer(128) As Byte
oFileStream.Seek(-128, SeekOrigin.End)
oFileStream.Read(bBuffer, 0, 128)
oFileStream.Close()

' Convert the Byte Array to a String
'Encoding(instEncoding = New ASCIIEncoding()) ' NB: Encoding
is an Abstract class
Dim instEncoding As Encoding = Encoding.ASCII
Dim id3Tag As String = instEncoding.GetString(bBuffer)

' If there is an attched ID3 v1.x TAG then read it
If (id3Tag.Substring(0, 3) = "TAG") Then

Title = id3Tag.Substring(3, 30).Trim()
Artist = id3Tag.Substring(33, 30).Trim()
Album = id3Tag.Substring(63, 30).Trim()
Year = id3Tag.Substring(93, 4).Trim()
Comment = id3Tag.Substring(97, 28).Trim()

' Get the track number if TAG conforms to ID3 v1.1
If (id3Tag(125) = "") Then
Track = bBuffer(126)
Else
Track = 0
End If
GenreID = bBuffer(127)

hasTag = True
Else

hasTag = False
End If
End Sub

End Class

Jun 25 '06 #1
2 1396
"wk" <sa******@gmail.com> schrieb:
I am reading a mp3 file's last 128 bytes and putting the text into
string variables.
What is happening is that the string is being stored with, probably
some wrong encoding or character, and hence has a " in front, and i
cant see the full string in VB 2005 express's debug mode. I have based
this off an example from the web.

I have spent a full day trying to debug this with a lot of different
ways, and now am exausted with ideas.

try giving the code any mp3 file on your disk, and then debug at line
75 of class1.vb to see the value of 'Title' variable.
Here is the code. When u run it, becuase of the problem said above, u
wont see the "<" in the messagebox


I didn't specifically analyze the code you provided, but maybe the string
contains a 'ControlChars.NullChar'. Null characters are interpreted as
string terminators by most Win32-based controls and forms in the .NET
Framework's class library.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jun 25 '06 #2
wk
Umm, well I confirm sheepishly that, that indeed was the problem :)
Thanks a lot for "literally" saving the day!

Jun 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Randy | last post by:
Hello, Is there an easy way to convert a string to a stream? Thanks
8
by: wkodie | last post by:
I'm having trouble encrypting/decrypting a simple string using the System.Security.Cryptography.TripleDESCryptoServiceProvider, etc... The encryption works, but the decryption does not properly...
2
by: Cole Shelton | last post by:
Hi all, I am simply trying to do a transform to a base 64 string and back, but for some reason, the FromBase64Transform is return less bytes than it should. I have verified that the base64...
9
by: Andrea | last post by:
how can I convert a byte to a string ? Any idea? Andrea
1
by: Default | last post by:
Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is VS files corrupted , or something else. that is the problems description: I am working on a small database project. I am...
4
by: Charlie | last post by:
Hi: I'm storing my dB connection in web.config file. Since it will be easily read by opening file, what is a good way to secure it? Thanks, Charlie
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
5
by: Tony | last post by:
Is there a quick and easy way to encrypt and decrypt a string in vb.net
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.