473,788 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.It em(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 2541
to************* *@uniroma1.it wrote:
I am extracting some field names from a table of a db (it's an
OledbSchemagui d table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.It em(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.Str ingBuilder

Function RemoveNothing(B yVal 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.ToStrin g
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
OledbSchemagui d table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.It em(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.replac e(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.Str ingBuilder

Function RemoveNothing(B yVal 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.ToStrin g
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
OledbSchemagui d table).

It occurs for some OleDbSchema driver that

NameDBField = cstr(DataRow.It em(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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim t As Date = Now

Dim s As String = "khjlkjddsdvasd vfasbasdsd" & _
"sdfsdsdfgbsdfg sdfhlkhlhlhlkhj " _
& Chr(0) & Chr(0)

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

MsgBox(Now.Subt ract(t).TotalMi lliseconds)

End Sub

Dim Scanner As New System.Text.Str ingBuilder
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.ToStrin g
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.Visua lBasic.Left(str String, intZeroPos -
1)
Else
Return strString
End If

End Function

Private Function RemoveNothing3( ByVal mystring As String) As String
Return mystring.Replac e(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=mystri ng.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim t As Date = Now

Dim s As String = "khjlkjddsdvasd vfasbasdsd" & _
"sdfsdsdfgbsdfg sdfhlkhlhlhlkhj " _
& Chr(0) & Chr(0)

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

MsgBox(Now.Subt ract(t).TotalMi lliseconds)

End Sub

Dim Scanner As New System.Text.Str ingBuilder
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.ToStrin g
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.Visua lBasic.Left(str String, intZeroPos -
1)
Else
Return strString
End If

End Function

Private Function RemoveNothing3( ByVal mystring As String) As String
Return mystring.Replac e(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 .GetOleDbSchema Table) 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 SchemaGuidColum ns As DataTable =
..OleDbConnecti on.GetOleDbSche maTable(System. Data.OleDb.OleD bSchemaGuid.Col umns,
New Object() {})
'...

The connection string for MySQL is like that:

Me.ConnectionSt ring = "Provider=MySQL Prov" & _
";User ID=" & UserId & _
";Password= " & Password & _
";Location= " &
Me.ServiceNameS erverNameLocati on & _
";Data Source=" &
Me.DatabaseCata log

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
OleDbConnectio n.GetOleDbSchem aTable) 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 SchemaGuidColum ns As DataTable =
.OleDbConnecti on.GetOleDbSche maTable(System. Data.OleDb.OleD bSchemaGuid.Col umns,
New Object() {})
'...

The connection string for MySQL is like that:

Me.ConnectionSt ring = "Provider=MySQL Prov" & _
";User ID=" & UserId & _
";Password= " & Password & _
";Location= " &
Me.ServiceName ServerNameLocat ion & _
";Data Source=" &
Me.DatabaseCat alog

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

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

Similar topics

24
3164
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 though I only allocated 5 characters in memory with new.
4
510
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 abc.text = "" The ' Some Cod End I For datetime's I'm currently using something like this If Not abc.ToShortDateString = "01/01/0001" The ' Some Cod
2
3423
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 raised a doubt in my mind on the same issue. Either through ignorance or incompetence, I've been unable to resolve some issues. 6.4.4.4p6 states...
5
3980
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 variable **var make it an array of pointers? I realize that 'char **var' is a pointer to a pointer of type char (I hope). And I realize that with var, var is actually a memory address (or at
8
10115
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) When I asked why, I was told that it facilitated calling it as:
61
3162
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 with "" it is - correct? The system seems to handle a null the same as "".
18
4064
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
2809
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 the result should be "pass____ what the result is where each underline char is a nothing char. I am about to write a function that will remove the nothing chars butI would like to know what is causing the problem and simply avoid it
20
3567
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
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.