ascii length??

  • Thread starter Thread starter Algren
  • Start date Start date
A

Algren

hi all,

I am wondering how I can get the ascii lengh of a string in VB.NET?
Especially that the string consists of alpha numerics as well as chinese
(double-byte) characters. Say I have a string "¢Ï¢Ð123" with the first 2
characters being double-byte, using Len() on that string would return me 5.
How can I get a value of 7 instead?? is there any VB.NET function that'd
achieve that?

Thanks a lot and your help's greatly appreciated.
 
just a thought haven't tried this
did you try to convert the string to a char array and take the length of
that (if the double-byte chars count as 2 ascii chars that might work)

hope it helps

eric
 
Hi Algren,

Ascii string (I will be before Armin), do you mean the amount of 7 bits
occurences in the string?

Normaly a string gives back the lenght of char in the used unicode. (I do
not think that is different with Chinese with other types).

I never heard of a mixed up string which has different types of unicode in
it.

But just my thoughts,

Cor
 
hi Cor,

First thanks for replying.

Cor said:
Hi Algren,

Ascii string (I will be before Armin), do you mean the amount of 7 bits
occurences in the string?
I think so. Just the effect of the first two characters being wider than
other alpha numerics
Normaly a string gives back the lenght of char in the used unicode. (I do
not think that is different with Chinese with other types).

I never heard of a mixed up string which has different types of unicode in
it.

Perhaps what I need is a way of distinguishing a double-byte word from
alpha-numerical characters in the same used unicode.
The problem is that with unicode I think every charater is treated as two
bytes.
 
Hi Algren,
Perhaps what I need is a way of distinguishing a double-byte word from
alpha-numerical characters in the same used unicode.
The problem is that with unicode I think every charater is treated as two
bytes.
That is what I know from it.

Cor
 
Algren said:
hi all,

I am wondering how I can get the ascii lengh of a string in VB.NET?
Especially that the string consists of alpha numerics as well as chinese
(double-byte) characters. Say I have a string "¢Ï¢Ð123" with the first 2
characters being double-byte, using Len() on that string would return me 5.
How can I get a value of 7 instead?? is there any VB.NET function that'd
achieve that?

Thanks a lot and your help's greatly appreciated.

The Len() function is provided for backwards compatability with VB6.
The "proper" way to obtain a string variable's current length is with
the String Class's .Length property. For example:

Dim myString as String

myString = "some value"
messagebox.show ("current length is " & myString.Length)

Does this give the same results?
 
Hi Zack,
The Len() function is provided for backwards compatability with VB6.
The "proper" way to obtain a string variable's current length is with
the String Class's .Length property. For example:

Dim myString as String

myString = "some value"
messagebox.show ("current length is " & myString.Length)

The string.length() function is provided for backwards compatabilitity with
C.

(I think that it else maybe had been count as all modern array's)

Len() is a full Net framework function (As is the string.length() function
also before you understand it wrong).

It are both "proper" ways to obtain a string variable's current length.

Just before people understand it wrong.

Cor
 
* "Algren said:
I am wondering how I can get the ascii lengh of a string in VB.NET?
Especially that the string consists of alpha numerics as well as chinese
(double-byte) characters. Say I have a string "¢Ï¢Ð123" with the first 2
characters being double-byte, using Len() on that string would return me 5.
How can I get a value of 7 instead?? is there any VB.NET function that'd
achieve that?

'System.Text.Encoding.ASCII.GetBytes', then get the length of the
returned array.
 
hi Zack,

Thanks for replying...
The Len() function is provided for backwards compatability with VB6.
The "proper" way to obtain a string variable's current length is with
the String Class's .Length property. For example:

Dim myString as String

myString = "some value"
messagebox.show ("current length is " & myString.Length)

Does this give the same results?

Yeah it does, unfortunately.
I guess I am looking for a way to break the existing unicode encoding in
VB.NET or manually parse my string to filter ANSI and double-byte
characters. Any ideas?
 
hi Herfried,
'System.Text.Encoding.ASCII.GetBytes', then get the length of the
returned array.

I tried it but it still gave me the same result. I think I'm doomed because
the string has been encoded to unicode already.
 
* "Algren said:
I tried it but it still gave me the same result. I think I'm doomed because
the string has been encoded to unicode already.

Mhm...
 
Hi Herfried,

Just see my first answer, this looks if the idea is that in a string can
have

8bitsChar,16bitsChar,7bitsChar,16BitsChar

I start to think that I become crazy because I only say that this is not the
situation.

Cor
 
Note, I'm not too familiar with this, but anyway:

It looks like ascii encoding literaly means only one byte per character - I
did run this code in a japanese machine and got the expected results:
Dim str As String = ChrW(30000) & ChrW(30000) & "123"
MsgBox(System.Text.Encoding.Default.GetByteCount(str))

this yields 7 bytes. I'm assuming that you could try to get what encoding
it is that you're writing files to disk and use that to get the byte count.

Hope that helps.

--------------------
From: "Cor" <[email protected]>
References: <e0J6zKe#[email protected]>
<[email protected]>
 
Back
Top