I am currently making a program that reads the ID tags from an MP3. Here is my problem or an example of my problem. Lets say I have the artist showen in a msgbox and the song title showen in a seperate msgbox like so:
msgbox(artist) msgbox(song)
The msgbox will appear and show the correct info. But lets say I do something like this:
msgbox(artist & " - " & song)
it will ONLY show the artist, but this doesn't happen all the time, depending on the MP3 that is read, it will display just as I want... What I really want to know is what can cause it to not display the rest of the string like I want it to It displays all the info fine if its seperate, but not when I try to combine it like above.
heres alittle code sniplet...
Dim
newName As String = ""mp3 =
New mp3TagClassmp3.fileToRead = fileOpen.FileName
Dim struct As New mp3TagClass.tagInfo Dim extra As New mp3TagClass.extraInfomp3.extractMP3Tag(struct, extra)
If extra.isTagPresent And struct.artist <> "" And struct.song <> "" ThennewName = struct.artist.ToString &
" - " & struct.song.ToStringEnd
If
Hope I explained my situation well enough. If someone could please tell me what causes this to happen with strings I would be very greatfull, as I remember this sometimes happening back when I used vb6 at my dads office.
Thanks alot.

Strange string problem in vb?
Paul Sanders
Glad we could get to the bottom of the issue by looking at the characters in the string.
BriTheProblem
Thats correct, it always displays the song in the first one, but not always in the second one...
I've also made a window that pops up displaying the info in serperate text boxes and it displays correctly there also... heres a Screen Shot of what I'm talking about.
Notice how the song selected in the list doesn't show the song title, but in the editor, which is displaying it seperatly shows it fine. Also notice the song above it shows the title... This isn't the first time this has happned to me.. So there must be something with the string "artist" that is making it not add the other strings :S
Also I did sometesting to have it put quotes around the artist string like so:
when the msgbox appears it displays like "Linkin Park
and doesn't show the last quote.. So not sure whats going on here, but I want to get to the bottom of it lol
Appel
JMicke
Thank you I will give that a try :)
Edit:
About the string maybe having a newline or return after it, I'm not 100% sure about this as this is my first time accualy using a listView controll but in textboxes and listboxes they always showed as little boxes for me specialy the linefeed chars (chr(10))
DilipK
On the strings that cause the problem. If you do the same artist song as
msgbox(song)
or
msgbox(artist & " - " & song)
Does it always display the song in the first code and not in the second.
For these songs if you put a breakpoint on the msgbox line and add a watch for song and artist to see what the value is do these display correctly in the watch window.
mzahmed
Ok so here are the results:
"Linkin Park" was the artist name I ran the function on... seems there are some hidden chars after the first 10 chars or something lol kinda weird..
Here is another Linkin Park as the author string...
And it does show the title after the author name...
So now my question is, what are those "invisible" chars that I cant see but are there, and how do I get rid of them lol, cause in the text box they arn't there the string is only 10 chars long.. Anyways thanks for that function helped alot ^.^
While I wait for someone to post an idea on how to get rid of them I'll try a few things.
Gungmas
Looks like there are NULL (0) characters tagged on at the end.
It is a common practice to terminate strings with a NULL (0) character in many languages (i.e. C & C++) and many native API functions rely on the fact that there is a NULL character at the end (that's basically how the function figures out where the string ends/how long the string is). In the managed world, strings don't depend on the string being NULL terminated (it keeps track of the length of the string in a separate field), but there are some issues with having NULL characters in strings, particularly when the string is going to be passed (directly or indirectly) to native code (which happens to be the case when setting the text for many controls)
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dv_vbcode/html/vbtskcodecreatingstringfromindividualcharactersvisualbasic.asp
The solution that you have will work fine. You can also use String.TrimEnd (it'll be slightly faster) but I don't think that performance will be an issue here...
Best regards,
Johan Stenberg
Daniel Kornev
Ok well thanks all of your guys help I found a solution!
I'm not sure if this is the best way to do it but its quick and easy.. Maybe instead use the .replace() method
Anyways heres how I did it
then you can just use it like so: fixString(someReallyMessedUpString) and thats it xD
Edit:
Found a way to use the replace method, thanks for all your help, this nightmare is over ^.^
Richdz
That was my first thought but this wouldnt necessarily explain why it is visible in the form that was generated to show the title - where it appears.
My though now is looking at the string it is showing as Break_ The_Habit - I'm looking at the underscore characters and trying to figure if they are really underscore characters in the tag or they are reflecting a different issue such as how in using & on a label to specify a shortcut and it then puts an underscore in there.
I'd like to look at what characters are actually in that string
Sub GetStringDetails(ByVal s As String, ByVal Filename As String)
Dim sOutput As String = ""
Dim icount As Integer = 0
Dim icountstring As String
For Each c As Char In s
icountstring = CType(icount, String)
sOutput = sOutput & icountstring & " " & Asc(c) & vbCrLf
icount = icount + 1
Next
My.Computer.FileSystem.WriteAllText(Filename, sOutput, False)
End Sub
Perhaps using a function like the above to export the ascii values of each of the characters in the string may shed some more light on what is happening.
Skipy
Could the artist name by any chance end with a newline or carriage return If so, you'll end up with a string that looks like
and since you only have once line in your textbox, you'll only see the first line...
Best regards,
Johan Stenberg
5Rock
I have found that sometimes, instead of using "&" to put two strings together, it is better to use "+". Textbox1.Text = artist + "-" + song
Cannot say why exactly, but, I have run into occasions where using the + sign worked better.
james
aka:Trucker