473,503 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to specify zero termination?

Lets say I was given a Char array as:
Dim Arr(size) As Char

and this array holds a string which ends with a C-Style zero termination.
I want to make this into a String object and cut it off at the end.

So in C# I could do:

String str = (new String(arr)).Trim('\0');

However in VB '\0' is not understood.

Please advice.

-- John
Nov 21 '05 #1
5 1757
John,
'\0' is a char literal in C#, VB.NET uses "x"c for char literals,
unfortunately VB.NET does not have any escaped characters.

However! VB.NET does have the ControlChars class that lists a number of
common escaped characters, such as ControlChars.NullChar, alternatively you
can simply use Chr(0) or ChrW(0).

So in VB.NET you can use either:

Dim str As String = New String(arr).Trim(ControlChars.NullChar)

Or I would consider:

Dim length As Integer = Array.IndexOf(arr, ControlChars.NullChar)
Dim str = New String(arr, 0, length)

Depending on the expected size of the strings the second might be better in
that it does not allocate 2 string objects, causing extra work for the GC.
For short strings I suspect the difference would be immaterial... Based on
extensive profiling I would pick one over the other...

Hope this helps
Jay

"John Smith" <jo********@x-formation.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
Lets say I was given a Char array as:
Dim Arr(size) As Char

and this array holds a string which ends with a C-Style zero termination.
I want to make this into a String object and cut it off at the end.

So in C# I could do:

String str = (new String(arr)).Trim('\0');

However in VB '\0' is not understood.

Please advice.

-- John

Nov 21 '05 #2
Jay,
'\0' is a char literal in C#, VB.NET uses "x"c for char literals,
unfortunately VB.NET does not have any escaped characters.

Just my opinion.

fortunately VBNet ...................................

I like more simple the values. When this kind of memonics are in programs I
am always hours busy finding the right tables. However that you know already
because this is something the same as using Regex.
(Just to show that it not have to be directly an omission by mistake).

:-)

Cor
Nov 21 '05 #3
Cor,
Huh?

I'm sorry but your statement makes NO sense! Can you explain what you are
attempting to say?

Thanks
Jay

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Jay,
'\0' is a char literal in C#, VB.NET uses "x"c for char literals,
unfortunately VB.NET does not have any escaped characters.

Just my opinion.

fortunately VBNet ...................................

I like more simple the values. When this kind of memonics are in programs
I am always hours busy finding the right tables. However that you know
already because this is something the same as using Regex.
(Just to show that it not have to be directly an omission by mistake).

:-)

Cor

Nov 21 '05 #4
Jay,

You say, "unfortunately" VB.NET does not have any escaped characters

Others like me say "fortunately".

I have by the way thought about this later when I had already written this
message. A long time ago I abanded books and started more too rely on
trustable Interenet sites. That is as we have seen a difference in approach
between us.

Things as those charachters are easy to find in books, while on Internet
that is often a hell.

It is just that we have another opinion, where I respect yours of course.

Cor
Nov 21 '05 #5
Cor,
You say, "unfortunately" VB.NET does not have any escaped characters

Others like me say "fortunately". Umm... My message is stating: its unfortunate for John.
It is just that we have another opinion, where I respect yours of course. Do we?

As I've stated in other posts I normally use ChrW in constants...

So I don't see a big need for escape characters either. Granted as you
suggest, you need to know what the character codes are that you want to use,
for displayable ones you can use the Character Map Windows Accessory. For
control chars, such as Tab & NewLine you need to know what they are or use
ControlChars...

FWIW: For me ControlChars.Tab says a lot more then "\t". Plus I don't need
to worry about when to use @ before the string. For example @"\t" when I
literally want "\t" in the string, not a string with the ControlChars.Tab in
it...

Thanks for the clarification!
Jay


"Cor Ligthert" <no************@planet.nl> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl... Jay,

You say, "unfortunately" VB.NET does not have any escaped characters

Others like me say "fortunately".

I have by the way thought about this later when I had already written this
message. A long time ago I abanded books and started more too rely on
trustable Interenet sites. That is as we have seen a difference in
approach between us.

Things as those charachters are easy to find in books, while on Internet
that is often a hell.

It is just that we have another opinion, where I respect yours of course.

Cor

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1346
by: Alexander Staubo | last post by:
Python does not seem to clean up gracefully on SIGTERM: The exit sequence is not invoked on termination, so the atexit module cannot be used to install shutdown logic. Further, while the signal...
2
2070
by: Jim McGrail | last post by:
Background: I am investigating a problem involving a windows .NET application that is being developed in C# with Visual Studio 2003. It is a multi-threaded application that uses MSMQ to...
9
13720
by: _link98 | last post by:
Normally I use the semicolon for statement delimiters in plain SQL scripts (for DDL, simple DML etc.). But inside SQL/PL I tend to use % or @ as statement delimiters. But other people prefer...
25
15585
by: Mantorok Redgormor | last post by:
Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. beyond this...
35
2536
by: Felix Kater | last post by:
The C-faq says that "The malloc/free implementation remembers the size of each block allocated and returned, so it is not necessary to remind it of the size when freeing." Could that length...
0
4405
by: Ricky Chan | last post by:
I am using DNSQuery API to get computer name from IP address. However, by below sample code, I don't know how to specify the DNS Address for the field (ByVal aipServers As Integer). any idea?...
669
25390
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
9
6863
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
0
1406
by: vsankar9 | last post by:
It's an Service Contracts From CRM. I need termination amount for who's the customer is terminated . End date - 15-DEC-2007 Termination as of date - 15-MAR-2007 Rate - 1000 (monthly rate ) ...
0
7201
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
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.