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

string equality

I read a list of name/value pairs from a remote (pocket pc + RAPI) registry
into a string array (3rd party wrapper for rapi registry objects).
As I check through each set, I test each name against "Completed" and will
skip the code if the test passes.
Unfortunately, the string returned to me in a watch shows as
"Completed\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"
(\0s ad nauseum) and this doesn't match "Completed" so the test fails.
Any idea what's going on here please?

string[] Imports = regkey.GetValueNames();

for (int nCount = Imports.GetLowerBound(0); nCount <=
Imports.GetUpperBound(0); nCount++)

{

FileName = (string)regkey.GetValue(Imports[nCount],"");

if (FileName == "")continue;

//if (Imports[nCount] == "Completed") continue;

if (Imports[nCount].Equals("Completed")) continue;

WriteRemote(FileName);

}
Nov 16 '05 #1
5 1549
Claire,

It looks like whatever your wrapper is, it is overallocating memory, and
assuming that the string will be compared up to the first null character in
the string.

What you want to do is find the index of the first null character, and
then trim off the rest. You can do this easily with the TrimEnd method on
the string class. You can do it like this:

// Trim the null characters off.
string trimmed = Imports[nCount].TrimEnd(new char[] { '\0' });

This should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Claire" <bl****@blahhhhh.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
I read a list of name/value pairs from a remote (pocket pc + RAPI) registry
into a string array (3rd party wrapper for rapi registry objects).
As I check through each set, I test each name against "Completed" and will
skip the code if the test passes.
Unfortunately, the string returned to me in a watch shows as
"Completed\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"
(\0s ad nauseum) and this doesn't match "Completed" so the test fails.
Any idea what's going on here please?

string[] Imports = regkey.GetValueNames();

for (int nCount = Imports.GetLowerBound(0); nCount <=
Imports.GetUpperBound(0); nCount++)

{

FileName = (string)regkey.GetValue(Imports[nCount],"");

if (FileName == "")continue;

//if (Imports[nCount] == "Completed") continue;

if (Imports[nCount].Equals("Completed")) continue;

WriteRemote(FileName);

}

Nov 16 '05 #2
Hello,

Can you just trim the end, and remove all the \0s?

Something like:

string a = "Completed\0\0\0\0\0\0";
a = a.TrimEnd('\0');

You think that would work for you?

--
Regards,
Kristofer Gafvert
http://www.ilopia.com
"Claire" <bl****@blahhhhh.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
I read a list of name/value pairs from a remote (pocket pc + RAPI) registry into a string array (3rd party wrapper for rapi registry objects).
As I check through each set, I test each name against "Completed" and will
skip the code if the test passes.
Unfortunately, the string returned to me in a watch shows as
"Completed\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0
\0" (\0s ad nauseum) and this doesn't match "Completed" so the test fails.
Any idea what's going on here please?

string[] Imports = regkey.GetValueNames();

for (int nCount = Imports.GetLowerBound(0); nCount <=
Imports.GetUpperBound(0); nCount++)

{

FileName = (string)regkey.GetValue(Imports[nCount],"");

if (FileName == "")continue;

//if (Imports[nCount] == "Completed") continue;

if (Imports[nCount].Equals("Completed")) continue;

WriteRemote(FileName);

}

Nov 16 '05 #3
thanks Nicholas
Nov 16 '05 #4
Hi Claire

You can Trim('\0') the string before testing it. That will strip away any occurances of \0.

string str = "Completed";
foreach(string s in Imports)
{
if(str.Equals(s.Trim('\0')))
continue;
WriteRemote
}

Btw, in C# the lower bound of an array is always 0, so

for(int nCount = 0; nCount <= ; Imports.Length - 1; nCount++)
{
FileName = (string)regkey.GetValue(Imports[nCount],"");

if (FileName == "")
continue;

if ((Imports[nCount].Trim('\0')).Equals("Completed"))
continue;

WriteRemote(FileName);
}

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5
Claire wrote:
Unfortunately, the string returned to me in a watch shows as
"Completed\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0"
(\0s ad nauseum) and this doesn't match "Completed" so the test fails.
Any idea what's going on here please?


No, but if you can live with it, the easy solution is to test against
"startsWith("Completed") in stead of equality.
Nov 16 '05 #6

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

Similar topics

10
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of...
40
by: Ike Naar | last post by:
In K&R "The C++ programming language (2nd ANSI C edition), the reference manual states (paragraphs 7.9 and 7.10) that pointer comparison is undefined for pointers that do not point to the same...
26
by: junky_fellow | last post by:
Consider the following piece of code: char *str = "Hello"; if (str = "Hello") printf("\nstring matches\n"); str is pointer to char and "Hello" is a string literal whose type is "array of...
4
by: beginner | last post by:
please help me. can't cast char to string , or something like that - can't remember exactly and not on my .net pc. But basically, i thought that "x" would be treated as a char in this case and...
4
by: Matt Burland | last post by:
I'm a little confused about the way the default equality operator works with classes. Here's the situation, I have two comboboxes that are each filled with different object (i.e. ComboBox1 contains...
19
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
26
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
11
by: Tony | last post by:
Hello! Below I have two different ways to test if the instance tb.Text contains the string "Programmer" So which one to use is it just a matter of taste ? Or could it be some advantage to one...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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.