How can I open a file in a way that'll show me the NullChars?

  • Thread starter Christian Blackburn
  • Start date
C

Christian Blackburn

Hi Gang,
I would like to open a compressed document of mine. The problem is part of
the compression algorithm contains character 0 which I need to detect. VB
sees character 0 as "" nothing and I can't detect nothing because 5 null
characters in a row would still be "". Does anyone know a way around this?
Do I open as binary or what? If so how?
Thanks in Advance,
Christian Blackburn
 
C

Cor

Hi Christian,
I Character "0" is not nothing, it is has the byte value 48 like character
"1" has 49.
Maybe it is the binary value 0 you try to evaluate.
That I think you can reach with
\\\\
dim a as char = chr(0)
////
I hopes this helps you a little bit.
Cor
 
C

Christian Blackburn

Hi Cor,
Thanks for the help. I think you are right that I was trying to detect
Chr(0), I assumed that was the nullchar, but as you have just said it's
chr(48). So as far as you know I should be able to detect each instance of
all 256 characters within the string datatype even when the string has more
than one character? You see I'm worried that the null characters won't be
added to the Len() value. Is my assumption correct?
Thanks again,
Christian
 
A

Armin Zingler

Christian Blackburn said:
Hi Cor,
Thanks for the help. I think you are right that I was trying to
detect Chr(0), I assumed that was the nullchar, but as you have just
said it's chr(48). So as far as you know I should be able to detect
each instance of all 256 characters within the string datatype even
when the string has more than one character? You see I'm worried
that the null characters won't be added to the Len() value. Is my
assumption correct? Thanks again,
Christian

You can work with Chr(0) like with any char. The only problem is that the
IDE does not _display_ the text behind chr(0) and you might get problems
when calling API functions, but working with chr(0) (and all other
characters) should not be a problem. Concerning the Len function:

Dim s As String = "abd" & Chr(0) & "efg"
MsgBox(Len(s))

Msgbox shows 7. So, I don't see the problem. You can also use s.Length.
 
S

Stephany Young

Nearly Christian. Cor put you little crook but ...

NullChar is Chr(0). It is aka vbNullChar.

Chr(48) is 0 aka Zero.

NullChar's are definitely included in the Len() and .Length values.

<string>.IndexOf(NullChar) will return the index of the first occurrence of
a NullChar in the string or -1 if the string does not contain any.

If you want to get rid of them use <string> = <string>.Replace(NullChar,"").
This will reduce the Len() or .Length values by the number of NullChar's
that were in the string originally.
 
C

Christian Blackburn

Hi Cor,
Okay I just checked an the NullChar is indeed Chr(0). I guess I got a
little confused there :). I read " I Character "0" is not nothing, it is
has the byte value 48 like character" and interpreted it as "The NulL
Character is not nothing, it is has the byte value 48...". It would seem my
interpreter is flawed, oh well Microsoft ain't got nothing on my interpreter
:).
Cheers,
Christian Blackburn
 
C

Christian Blackburn

Hi Stephany,
Wow I think you're the first woman I've seen in this group. Of course with
so many foreigners in this group I might not recognize a female name if she
was from another nationality.

You seem to have good answers.
Nearly Christian. Cor put you little crook but ...

NullChar is Chr(0). It is aka vbNullChar.

Good that was what I had always thought :).
Chr(48) is 0 aka Zero.

NullChar's are definitely included in the Len() and .Length values.

I was not aware of that though and that's good to know :).

<string>.IndexOf(NullChar) will return the index of the first occurrence of
a NullChar in the string or -1 if the string does not contain any.

Hey thanks I saw that and wondered what the hell it did, but never bothered
to read the bloated MSDN help on it. That's an excellent function it's like
a quick version of Instr.
If you want to get rid of them use <string> =
This will reduce the Len() or .Length values by the number of NullChar's
that were in the string originally.

Thanks for all the help,
Christian Blackburn
 
C

Christian Blackburn

Hi Armin,
Yes I think you're right, I was expecting a "AB " where the null character
was when I moused over the string variable's value.
Thanks Again,
Christian Blackburn
 
C

Cor

"Christian Blackburn
Thanks for the help. I think you are right that I was trying to detect
Chr(0), I assumed that was the nullchar, but as you have just said it's
chr(48). So as far as you know I should be able to detect each instance of
all 256 characters within the string datatype even when the string has more
than one character? You see I'm worried that the null characters won't be
added to the Len() value. Is my assumption correct?

Some code to test a lot of thinks that you did ask last hours
When you use this, with me I saw that the string lengths are given correct.
\\\\
Dim ls, lsa, iAsChar As String
Dim i As Integer
Dim s As String = ("00000000")
i = Convert.ToInt32(s, 2)
iAsChar = Chr(i)
For y As Integer = 0 To 9
ls = ls & Asc(iAsChar) & Asc("0")
lsa = lsa & iAsChar & "0"
Next
MessageBox.Show(ls.Length.ToString & "=" & ls & "||" &
Len(lsa).ToString & "=" & lsa)
/////
I did use the length member and the Len function. The results are the same
if you change them.
Cor
 
C

Cor

Stephany,
The vbNullChar is the binary value zero.
0 is the arabian charachter for the value zero. It is also used in most
modern European languages.
:)
Cor
 
C

Cor

Christian
I doubt it, but I don't know what an aka is.
But important for you is, that you understand that 48 is only a codenumber
in some code tables and absolute not in all code tables.
It is never a value (except of course the code value).
Cor
 
C

Christian Blackburn

Hi Cor,
Thanks that is a good example. And I do appreciate what you were talking
about with the code pages. I definitely get what you're saying. That those
256 characters can mean anything you want based on a variety situations,
localizations, and formats.
Well Adios,
Christian Blackburn
 
H

Herfried K. Wagner [MVP]

Hello,

Cor said:
That I think you can reach with
\\\\
dim a as char = chr(0)

Notice that the nullchar is available through 'ControlChars.NullChar' too in
VB.NET.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top