473,407 Members | 2,676 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,407 software developers and data experts.

Nothing as a char of a string

I am extracting some field names from a table of a db (it's an
OledbSchemaguid table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.Item(3))

return a string that is composed by the characters of the field name,
for instance MYFIELD plus 1 Nothing. I know that the Nothing is there
because, since I was having a lot of problem with these strange strings
I have scanned them char by char.

This happens for any string extracted from any of the oledbschemaguid
tables using a certain OleDbSchema driver: there is always a char (the
last one ) equal to NOTHING.

Clearly, I would like to avoid the necessity to do the scan to remove
the strange Nothing char. Even the trimEnd instruction does not work,
and these strings cause general malfunnction of the program (for
instance prevent any string concatenation).

I cannot explain this strange thing. Does anybody have any idea how the
Nothing char can appear in the string and what is the best way to get
rid of it?

-t

Apr 14 '06 #1
10 2518
to**************@uniroma1.it wrote:
I am extracting some field names from a table of a db (it's an
OledbSchemaguid table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.Item(3))

return a string that is composed by the characters of the field name,
for instance MYFIELD plus 1 Nothing. I know that the Nothing is there
because, since I was having a lot of problem with these strange strings
I have scanned them char by char.

This happens for any string extracted from any of the oledbschemaguid
tables using a certain OleDbSchema driver: there is always a char (the
last one ) equal to NOTHING.

Clearly, I would like to avoid the necessity to do the scan to remove
the strange Nothing char. Even the trimEnd instruction does not work,
and these strings cause general malfunnction of the program (for
instance prevent any string concatenation).

I cannot explain this strange thing. Does anybody have any idea how the
Nothing char can appear in the string and what is the best way to get
rid of it?

-t

That nothing character is the \0 from C++ and similar languages that
terminate a string with the NULL character. VB doesn't really
understand this character, and can't concatenate anything to it.
Try using this function for anything you get back from the OleDbSchema:

Private Function StripTerminator(ByVal strString As String) As String
'Strings returned from Windows end in chr(0). It needs to be
removed for VB.'

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Tom
Apr 14 '06 #2

Thank you Tom! :) that's very enlighting, and thank you very much for
the code you kindly provided, which is certainly faster than the one I
was using temporarily:

Dim Scanner As New System.Text.StringBuilder

Function RemoveNothing(ByVal Text As String) As String
Scanner.Length = 0
For Each u As Char In Text
If Not u = Nothing Then Scanner.Append(u)
Next u
Return Scanner.ToString
End Function

Actually I was afraid that some strange chars could be found in any
position. But your explanation has clarified that it can be found only
at the end (I hope!).

Actually, I do not understand why that character is there, while in all
the other OleDB provider I have tried (I tried almost all of them) I
never saw it.

In this case I am talking about MyOleDB, the one available for MYSQL
(it seems quite primitive, must say). It is strange that I did not hear
much complaint around: probably not many people are actually using it.

Is that a bug of the OLEDB provider or it is possible in principle
that, given the specifications to create OleDB Drivers, that strange
terminator chars could be found in the SchemaGuid tables?

Thank you VERY much!!

-tom


tomb ha scritto:
to**************@uniroma1.it wrote:
I am extracting some field names from a table of a db (it's an
OledbSchemaguid table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.Item(3))

return a string that is composed by the characters of the field name,
for instance MYFIELD plus 1 Nothing. I know that the Nothing is there
because, since I was having a lot of problem with these strange strings
I have scanned them char by char.

This happens for any string extracted from any of the oledbschemaguid
tables using a certain OleDbSchema driver: there is always a char (the
last one ) equal to NOTHING.

Clearly, I would like to avoid the necessity to do the scan to remove
the strange Nothing char. Even the trimEnd instruction does not work,
and these strings cause general malfunnction of the program (for
instance prevent any string concatenation).

I cannot explain this strange thing. Does anybody have any idea how the
Nothing char can appear in the string and what is the best way to get
rid of it?

-t

That nothing character is the \0 from C++ and similar languages that
terminate a string with the NULL character. VB doesn't really
understand this character, and can't concatenate anything to it.
Try using this function for anything you get back from the OleDbSchema:

Private Function StripTerminator(ByVal strString As String) As String
'Strings returned from Windows end in chr(0). It needs to be
removed for VB.'

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Tom


Apr 14 '06 #3
You might try mystring = mystring.replace(chr(0), "")
--
Dennis in Houston
"to**************@uniroma1.it" wrote:

Thank you Tom! :) that's very enlighting, and thank you very much for
the code you kindly provided, which is certainly faster than the one I
was using temporarily:

Dim Scanner As New System.Text.StringBuilder

Function RemoveNothing(ByVal Text As String) As String
Scanner.Length = 0
For Each u As Char In Text
If Not u = Nothing Then Scanner.Append(u)
Next u
Return Scanner.ToString
End Function

Actually I was afraid that some strange chars could be found in any
position. But your explanation has clarified that it can be found only
at the end (I hope!).

Actually, I do not understand why that character is there, while in all
the other OleDB provider I have tried (I tried almost all of them) I
never saw it.

In this case I am talking about MyOleDB, the one available for MYSQL
(it seems quite primitive, must say). It is strange that I did not hear
much complaint around: probably not many people are actually using it.

Is that a bug of the OLEDB provider or it is possible in principle
that, given the specifications to create OleDB Drivers, that strange
terminator chars could be found in the SchemaGuid tables?

Thank you VERY much!!

-tom


tomb ha scritto:
to**************@uniroma1.it wrote:
I am extracting some field names from a table of a db (it's an
OledbSchemaguid table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.Item(3))

return a string that is composed by the characters of the field name,
for instance MYFIELD plus 1 Nothing. I know that the Nothing is there
because, since I was having a lot of problem with these strange strings
I have scanned them char by char.

This happens for any string extracted from any of the oledbschemaguid
tables using a certain OleDbSchema driver: there is always a char (the
last one ) equal to NOTHING.

Clearly, I would like to avoid the necessity to do the scan to remove
the strange Nothing char. Even the trimEnd instruction does not work,
and these strings cause general malfunnction of the program (for
instance prevent any string concatenation).

I cannot explain this strange thing. Does anybody have any idea how the
Nothing char can appear in the string and what is the best way to get
rid of it?

-t

That nothing character is the \0 from C++ and similar languages that
terminate a string with the NULL character. VB doesn't really
understand this character, and can't concatenate anything to it.
Try using this function for anything you get back from the OleDbSchema:

Private Function StripTerminator(ByVal strString As String) As String
'Strings returned from Windows end in chr(0). It needs to be
removed for VB.'

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
Tom


Apr 14 '06 #4
Thanks Dennis! :)

at this point I am really curious to get an idea of the respective
performance of the 3 solutions which
we have seen (although they are not really equivalent) ...

let's see ... here is the result of a quick and primitive test :

'TIME:
'RemoveNothing1 - around 10.000
'RemoveNothing2 - around 670
'RemoveNothing3 - around 1200

mmm .... actually I expected the replace to do better, as anyway
"InStr" id done through linear search (?) ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As Date = Now

Dim s As String = "khjlkjddsdvasdvfasbasdsd" & _
"sdfsdsdfgbsdfgsdfhlkhlhlhlkhj" _
& Chr(0) & Chr(0)

For i As Integer = 0 To 1000000
RemoveNothing3(s)
Next i

MsgBox(Now.Subtract(t).TotalMilliseconds)

End Sub

Dim Scanner As New System.Text.StringBuilder
Function RemoveNothing1(ByVal Text As String) As String
Scanner.Length = 0
For Each u As Char In Text
If Not u = Nothing Then Scanner.Append(u)
Next u
Return Scanner.ToString
End Function

Private Function RemoveNothing2(ByVal strString As String) As
String
'Strings returned from Windows end in chr(0). It needs to be
'removed for VB.'

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr(0))
If intZeroPos > 0 Then
Return Microsoft.VisualBasic.Left(strString, intZeroPos -
1)
Else
Return strString
End If

End Function

Private Function RemoveNothing3(ByVal mystring As String) As String
Return mystring.Replace(Chr(0), "")
End Function

Apr 15 '06 #5
Thanks for sharing your timing test...it's as I suspected it would be.
However, if you have only a chr(0) at the end of the string, you might try
mystring=mystring.trimend(chr(0)). This might be faster. Also, if there are
several embedded chr(0)'s in the string, other than at the end, then I
suspect method 3 with the .replace method will be faster than 2.
--
Dennis in Houston
"to**************@uniroma1.it" wrote:
Thanks Dennis! :)

at this point I am really curious to get an idea of the respective
performance of the 3 solutions which
we have seen (although they are not really equivalent) ...

let's see ... here is the result of a quick and primitive test :

'TIME:
'RemoveNothing1 - around 10.000
'RemoveNothing2 - around 670
'RemoveNothing3 - around 1200

mmm .... actually I expected the replace to do better, as anyway
"InStr" id done through linear search (?) ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As Date = Now

Dim s As String = "khjlkjddsdvasdvfasbasdsd" & _
"sdfsdsdfgbsdfgsdfhlkhlhlhlkhj" _
& Chr(0) & Chr(0)

For i As Integer = 0 To 1000000
RemoveNothing3(s)
Next i

MsgBox(Now.Subtract(t).TotalMilliseconds)

End Sub

Dim Scanner As New System.Text.StringBuilder
Function RemoveNothing1(ByVal Text As String) As String
Scanner.Length = 0
For Each u As Char In Text
If Not u = Nothing Then Scanner.Append(u)
Next u
Return Scanner.ToString
End Function

Private Function RemoveNothing2(ByVal strString As String) As
String
'Strings returned from Windows end in chr(0). It needs to be
'removed for VB.'

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr(0))
If intZeroPos > 0 Then
Return Microsoft.VisualBasic.Left(strString, intZeroPos -
1)
Else
Return strString
End If

End Function

Private Function RemoveNothing3(ByVal mystring As String) As String
Return mystring.Replace(Chr(0), "")
End Function

Apr 16 '06 #6
I tried it.
Under same conditions, it's around 600.

Yes, method 3 is more general, as it replaces vbNullChar everywhere.
The last method proposed is probably the one which sufficies in this
specific
situation ("bug" in MyOleDB driver).

The key thing has been noticing (Tomb) that the "nothing" value is
caused by the terminator
vbNullchar (\0) ...

-tom

Apr 16 '06 #7
to**************@uniroma1.it wrote:
I tried it.
Under same conditions, it's around 600.

Yes, method 3 is more general, as it replaces vbNullChar everywhere.
The last method proposed is probably the one which sufficies in this
specific
situation ("bug" in MyOleDB driver).

The key thing has been noticing (Tomb) that the "nothing" value is
caused by the terminator
vbNullchar (\0) ...

-tom

Actually, this is not a bug at all. The C related environments all use
the chr(0) as a string terminator, as does the Windows OS. If you ever
used the Windows dll call to read a registry entry, it is returned from
the OS with that very terminator. MySql obviously was written in that
kind of language. VB actually has that terminator, it's just that we
don't see it - it is hidden fom us by the development environment. VB
uses a string descriptor rather than the actual array of characters
holding the string. I'm sure the originators of VB had a very good
reason for doing this, but it can get in the way of playing nice with
the other guys.
Anyway, these were some interesting approaches to the situation. It was
a learning experience for me also. And thanks for the recognition.

Tom
Apr 17 '06 #8
Hi Tom :)

I understood that. What I meant talking about "bug" is the following.

If you extract (through the command
OleDbConnection.GetOleDbSchemaTable) the SchemaTables using ANY other
OleDb driver (Oracle, Sybase, VFP, SQL server, jet, etc...) you will
get a clean list of items.

When you use MyOleDB OleDbDriver for MYSQL, * and only for this one * ,
each string in the schema shows that problem (a vbNullChar appended to
each string).

You can make a trial yourself (the driver is here:
http://sourceforge.net/projects/myoledb/ ). I use something like:

Try
Using SchemaGuidColumns As DataTable =
..OleDbConnection.GetOleDbSchemaTable(System.Data. OleDb.OleDbSchemaGuid.Columns,
New Object() {})
'...

The connection string for MySQL is like that:

Me.ConnectionString = "Provider=MySQLProv" & _
";User ID=" & UserId & _
";Password=" & Password & _
";Location=" &
Me.ServiceNameServerNameLocation & _
";Data Source=" &
Me.DatabaseCatalog

Since this happens only for MyOLEDB driver, I suspect that this
situation may be defined as "bug", even though I do not know the reason
why this happens (perhaps the programmer of the driver has used 2
terminators (??) )

Any idea?

-tommaso

Apr 17 '06 #9
I haven't encountered any of this. It is only my C++ experience that
enabled me to decypher what that ending character is. But I appreciate
you sharing the work you've done with this, it will certainly be useful
in the very near future, as I am beginning a project that uses MySql as
the back-end.

Tom

to**************@uniroma1.it wrote:
Hi Tom :)

I understood that. What I meant talking about "bug" is the following.

If you extract (through the command
OleDbConnection.GetOleDbSchemaTable) the SchemaTables using ANY other
OleDb driver (Oracle, Sybase, VFP, SQL server, jet, etc...) you will
get a clean list of items.

When you use MyOleDB OleDbDriver for MYSQL, * and only for this one * ,
each string in the schema shows that problem (a vbNullChar appended to
each string).

You can make a trial yourself (the driver is here:
http://sourceforge.net/projects/myoledb/ ). I use something like:

Try
Using SchemaGuidColumns As DataTable =
.OleDbConnection.GetOleDbSchemaTable(System.Data. OleDb.OleDbSchemaGuid.Columns,
New Object() {})
'...

The connection string for MySQL is like that:

Me.ConnectionString = "Provider=MySQLProv" & _
";User ID=" & UserId & _
";Password=" & Password & _
";Location=" &
Me.ServiceNameServerNameLocation & _
";Data Source=" &
Me.DatabaseCatalog

Since this happens only for MyOLEDB driver, I suspect that this
situation may be defined as "bug", even though I do not know the reason
why this happens (perhaps the programmer of the driver has used 2
terminators (??) )

Any idea?

-tommaso

Apr 17 '06 #10
Good. When you find out problems on that area, let's share them (just
drop an e-mail or post here), I am very interested on these (or
actually, on their solution :) and, for some, I already have some
solutions... )

for instance, another thing I have noticed is that MyOledb does not
seem to like at all table aliases ...

-tom

tomb ha scritto:
I haven't encountered any of this. It is only my C++ experience that
enabled me to decypher what that ending character is. But I appreciate
you sharing the work you've done with this, it will certainly be useful
in the very near future, as I am beginning a project that uses MySql as
the back-end.

Tom

to**************@uniroma1.it wrote:
Hi Tom :)

I understood that. What I meant talking about "bug" is the following.

If you extract (through the command
OleDbConnection.GetOleDbSchemaTable) the SchemaTables using ANY other
OleDb driver (Oracle, Sybase, VFP, SQL server, jet, etc...) you will
get a clean list of items.

When you use MyOleDB OleDbDriver for MYSQL, * and only for this one * ,
each string in the schema shows that problem (a vbNullChar appended to
each string).

You can make a trial yourself (the driver is here:
http://sourceforge.net/projects/myoledb/ ). I use something like:

Try
Using SchemaGuidColumns As DataTable =
.OleDbConnection.GetOleDbSchemaTable(System.Data. OleDb.OleDbSchemaGuid.Columns,
New Object() {})
'...

The connection string for MySQL is like that:

Me.ConnectionString = "Provider=MySQLProv" & _
";User ID=" & UserId & _
";Password=" & Password & _
";Location=" &
Me.ServiceNameServerNameLocation & _
";Data Source=" &
Me.DatabaseCatalog

Since this happens only for MyOLEDB driver, I suspect that this
situation may be defined as "bug", even though I do not know the reason
why this happens (perhaps the programmer of the driver has used 2
terminators (??) )

Any idea?

-tommaso


Apr 17 '06 #11

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

Similar topics

24
by: Norm | last post by:
Could someone explain for me what is happening here? char *string; string = new char; string = "This is the string"; cout << string << std::endl; The output contains (This the string) even...
4
by: Nathon Dalton | last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples For string I use this If Not abc.text Is Nothing AndAlso Not...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
8
by: andrew.fabbro | last post by:
In a different newsgroup, I was told that a function I'd written that looked like this: void myfunc (char * somestring_ptr) should instead be void myfunc (const char * somestring_ptr) ...
61
by: academic | last post by:
When I declare a reference variable I initialize it to Nothing. Now I'm wondering if that best for String variables - is "" better? With Nothing I assume no memory is set aside nor GC'ed But...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.