Unable to append string in VB

  • Thread starter Thread starter Two Beards
  • Start date Start date
T

Two Beards

Hi, I'm new to VB and .net so I may be mising something. I am trying to
dynamically build some SQL by appending to a string. Part of the SQL
comes from an mp3 id tag I have extracted from a file and stored in a
string. I can do all the normal stuff with the string like msgbox and I
can append it to another string but I cannot append to the end of it.

I have tried things like trim and using a string builder but it still
won't work.

Any advice would be greatly appreciated.

Cheers
Craig
 
* Two Beards said:
Hi, I'm new to VB and .net so I may be mising something. I am trying to
dynamically build some SQL by appending to a string. Part of the SQL
comes from an mp3 id tag I have extracted from a file and stored in a
string. I can do all the normal stuff with the string like msgbox and I
can append it to another string but I cannot append to the end of it.

I have tried things like trim and using a string builder but it still
won't work.

It's hard to give an answer without knowing the code. Make sure that
there are no 'ControlChar.NullChar' characters in your string. You can
use 'Strings.InStr' to detect the and then use 'Strings.Left' to cut out
the part in front of this characters.
 
cheers, I did the following and found that the problem is control
characters. It seems that it returns a 30 char string every time. The
replace fixes the problem.

If album.EndsWith(ControlChars.NullChar) Then
album = album.Replace(ControlChars.NullChar, "")
MsgBox(album + "...test...")
End If


Thanks for your help.
 
You mentioned String.Left in your reply. I know that you can use code like a
= left(b,10) to get the 10 left most characters. However, the String class
member in the MSDN doesn't list a left or right method or property. Is
something like a = b.left(10) legal? I am trying to avoid the old Left and
right inherent in Visual Basic and stick to the string class but I't
cumbersome sometimes because using Left(a,10) where a is only "" gives a ""
result in visual basic but the string class a.substring(0,10) gives an error
when a="". By the way, I very much enjoy reading your replies to the news
group and have learned a lot from your replies to others as well as myself.
Thanks a lot.
 
You mentioned String.Left in your reply. I know that you can use code like a
= left(b,10) to get the 10 left most characters. However, the String class
member in the MSDN doesn't list a left or right method or property. Is
something like a = b.left(10) legal?

No, there is no .Left method, it's a shared function in the Strings (not
String, re-read Herfried's post carefully) class in the VB library. In
other words,

a = Left(b,10)

as you suspect.
I am trying to avoid the old Left and
right inherent in Visual Basic and stick to the string class but I't
cumbersome sometimes because using Left(a,10) where a is only "" gives a ""
result in visual basic but the string class a.substring(0,10) gives an error
when a="".

True, but in this case it doesn't matter, since your index is the result
of a search and thus the string is guaranteed to be that length. BTW,
depending on your specific needs here, it may be easier and more robust
to simply replace NullChar with an empty string.
 
* =?Utf-8?B?RGVubmlz?= said:
You mentioned String.Left in your reply. I know that you can use code like a
= left(b,10) to get the 10 left most characters. However, the String class
member in the MSDN doesn't list a left or right method or property. Is
something like a = b.left(10) legal?

No, it's not. You will have to use 'Substring' if you want to use a
method of your string object.
I am trying to avoid the old Left and right inherent in Visual Basic
and stick to the string class but I't cumbersome sometimes because using

Newer is not necessarily better.
Left(a,10) where a is only "" gives a "" result in visual basic but
the string class a.substring(0,10) gives an error when a="".

ACK. That's indeed very annoying. That's why I keep using the
functions provided in the 'Strings' module.
By the way, I very much enjoy reading your replies to the news
group and have learned a lot from your replies to others as well as myself.
Thanks a lot.

:-)
 
The primary reason that I was trying to stick to the classes rather than
revert to Visual Basic Language was the possibility that Microsoft will, in
some future relese of VB.Net, eliminate the older Visual Basic functions such
as Left, Right, and Mid. Hey, thank for your info and opinion on this topic.
 
* =?Utf-8?B?RGVubmlz?= said:
The primary reason that I was trying to stick to the classes rather than
revert to Visual Basic Language was the possibility that Microsoft will, in
some future relese of VB.Net, eliminate the older Visual Basic functions such
as Left, Right, and Mid.

NO! That's definitely not true. Microsoft has /never/ said that these
functions will be removed and there is absolutely no reason to remove
them. They are part of VB.NET now and will stay part of VB.NET. There
will be many changes to VB.NET, but I assume that these functions
are/will be one of the most stable parts of the language.
 
Back
Top