472,971 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,971 software developers and data experts.

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 "¢Ï¢Ð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.
Nov 20 '05 #1
13 4246
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 "¢Ï¢Ð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.

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 "¢Ï¢Ð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?

Nov 20 '05 #3
hi Eric,

I tried that and it still gave the same result.

Thanks

"EricJ" <er********@ThiSbitconsult.be.RE> ¦b¶l¥ó
news:40*********************@news.skynet.be ¤¤¼¶¼g...
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 "¢Ï¢Ð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.


Nov 20 '05 #4
hi Cor,

First thanks for replying.

"Cor" <no*@non.com> ¦b¶l¥ó news:OF****************@TK2MSFTNGP11.phx.gbl ¤¤¼¶
¼g...
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 "¢Ï¢Ð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?


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 "¢Ï¢Ð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?
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 "¢Ï¢Ð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.

--
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: DraguVaso | last post by:
Hi, For my SMS-application I need to be able to send characters with accents (like é and à). But this doesn't seem to work in Text Mode, so i will need to do it in PDU Mode. Does anybody has...
5
by: mail2atulmehta | last post by:
I have a question. how to generate two files, one in UTF-8, the other in ASCII with the same column length SO that when i do the conversion from utf-8 to ascii, the column length does not change ....
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
5
by: Meenu Mehta | last post by:
I have a question. how to generate two files, one in UTF-8, the other in ASCII with the same column length SO that when i do the conversion from utf-8 to ascii or vice versa, the column length...
5
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography ...
6
by: Friso Wiskerke | last post by:
Hi all, I'm creating a fixed length textfile with data which is sent out to a third-party which in turn reads the file and processes it. Some of the characters are not part of the lower ASCII...
3
by: devgrt | last post by:
C#: I have a buffer that is populated with char data from a DLL: byte ret = new byte; I want to convert to a C# string: string msg = Encoding.ASCII.GetString(ret, 0, ret.Length); The problem...
18
by: John | last post by:
Hi, I'm a beginner is using C# and .net. I have big legacy files that stores various values (ints, bytes, strings) and want to read them into a C# programme so that I can store them in a...
6
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me....
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.