473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 4264
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.