468,457 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

ascii length??

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 "AB123" 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.
Nov 20 '05 #1
13 4072
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

"Algren" <co**********@yahoo.com.NO_SPAM> wrote in message
news:e0****************@tk2msftngp13.phx.gbl...
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 "AB123" 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.

Nov 20 '05 #2
Cor
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


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 "AB123" 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?

Nov 20 '05 #3
hi Eric,

I tried that and it still gave the same result.

Thanks

"EricJ" <er********@ThiSbitconsult.be.RE> 在郵件
news:40*********************@news.skynet.be 中撰寫...
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

"Algren" <co**********@yahoo.com.NO_SPAM> wrote in message
news:e0****************@tk2msftngp13.phx.gbl...
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 "AB123" 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.


Nov 20 '05 #4
hi Cor,

First thanks for replying.

"Cor" <no*@non.com> 在郵件 news:OF****************@TK2MSFTNGP11.phx.gbl 中撰
寫...
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.

But just my thoughts,

Cor


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 "AB123" 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?


Nov 20 '05 #5
Cor
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
Nov 20 '05 #6
"Algren" <co**********@yahoo.com.NO_SPAM> wrote in message news:<e0**************@tk2msftngp13.phx.gbl>...
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 "AB123" 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?
Nov 20 '05 #7
Cor
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


Nov 20 '05 #8
* "Algren" <co**********@yahoo.com.NO_SPAM> scripsit:
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 "AB123" 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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
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?
Nov 20 '05 #10
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.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #11
* "Algren" <co**********@yahoo.com.NO_SPAM> scripsit:
'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.


Mhm...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>

..NET FAQs: <http://www.mvps.org/dotnet/dotnet/faqs/> (German)
Nov 20 '05 #12
Cor
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
Nov 20 '05 #13
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(s tr))

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" <no*@non.com>
References: <e0**************@tk2msftngp13.phx.gbl> <c1*************@ID-208219.news.uni-berlin.de>
<uD**************@tk2msftngp13.phx.gbl>
<c1*************@ID-208219.news.uni-berlin.de>Subject: Re: ascii length??
Date: Tue, 24 Feb 2004 10:50:01 +0100
Lines: 13
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <e2**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: ip3e830773.speed.planet.nl 62.131.7.115
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:184276
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

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 thesituation.

Cor


Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by DraguVaso | last post: by
5 posts views Thread by mail2atulmehta | last post: by
5 posts views Thread by Meenu Mehta | last post: by
5 posts views Thread by Sia Jai Sung | last post: by
6 posts views Thread by Friso Wiskerke | last post: by
3 posts views Thread by devgrt | last post: by
18 posts views Thread by John | last post: by
9 posts views Thread by =?Utf-8?B?RGFu?= | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.