473,385 Members | 1,492 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,385 software developers and data experts.

Testing for End of string

Hi all,

I'm trying to test for the end of a string. I know that within C++,
it's '\0'; how do I test for it within VB.NET?

Thanks,
Eric
Nov 21 '05 #1
3 7677
Eric A. Johnson wrote:
I'm trying to test for the end of a string. I know that within C++,
it's '\0'; how do I test for it within VB.NET?


Are you testing character by character? How are you reading the
string? To my knowledge, VB strings are terminated by any particular
character. Can't you compare your position in the string with the
string length? What are you trying to do?

Nov 21 '05 #2

Eric A. Johnson wrote:
Hi all,

I'm trying to test for the end of a string. I know that within C++,
it's '\0'; how do I test for it within VB.NET?


Strings in .NET are a proper type, rather than just being arrays of
char, as they are in C and C++. Therefore without further context it
doesn't really make sense to talk about 'testing for the end of a
string' - if you have a String, you have a String. What are you trying
to do?

--
Larry Lard
Replies to group please

Nov 21 '05 #3
While .NET strings do not have a terminating character as such, the
nullchar will act like one if the string is displayed. Like this...
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click

Dim tstr As System.String = "ABCDEFGHJKLMN"
Dim newchar As Char
Dim bbyte() As Byte = {0}
newchar = System.Text.Encoding.ASCII.GetChars(bbyte)(0)
tstr = tstr.Replace("D", newchar)
System.Windows.Forms.MessageBox.Show(tstr)
-->> shows "ABC"
System.Windows.Forms.MessageBox.Show(tstr.Length.T oString)
-->> shows "13"

System.Windows.Forms.MessageBox.Show(tstr.IndexOf( newchar).ToString)
-->> shows "3"
End Sub

So while the string itself will hold the extra characters, the normal
way of showing it will not display past the nullchar.

The above code is a bit of a stretch to prove a point, but it can
happen while working with some API's that use string buffers passed
byref, communications when you have a buffer to fill and you only get
a partial message, etc.

You need to find where the end of the string that you want is located
and that is where you would use String.IndexOf

HTH,
Barry


On Tue, 18 Oct 2005 18:41:30 +0200, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:
You don't need to test for the end because the length of the string is
provided. .NET strings do not have a terminating character. All the
characters in the string's character array are valid.


bceggersATcomcastDOTnet
Nov 21 '05 #4

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

Similar topics

3
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules...
2
by: Naveen Mukkelli | last post by:
Hi, I'm writing a client/server application using C#. The server accepts connecitons asynchronously, using BeginAccept/EndAccept. Is there any way we can write some unit tests(NUnit) to test...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
1
by: google1 | last post by:
Has anyone written this one? Seen such a thing? Please send me a link: Skill Testing Question Exploder --------------------------------------------- Basically the plan is to create the...
9
by: tinnews | last post by:
What's the neatest and/or most efficient way of testing if one of a set of strings (contained in a dictionary, list or similar) is a sub-string of a given string? I.e. I have a string delivered...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
1
by: Alexnb | last post by:
Okay, I have a fix for this problem, but it is messy and I think there might be a better way. Heres an example: Lets say I have a string: "My name is alex" and I have another string "My name...
2
by: Edwin.Madari | last post by:
use re module import re template = '^My name is alex' astring = 'My name is alex, and I like pie' if re.match(template, astring): print 'Found it' else: print '%s does not begin with %s' %...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.