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

String comparison / modification (Bug????)

Dim
I found that C# has some buggy ways to process string across methods.
I have a class with on global string var and a method where i add / remove
from this string
Consider it a buffer... with some values and separators

class
{
private string globalvar = "";

private void manipulate (whattodo ) //substring, join, etc....
{
some manipulation on globalvar...
some join here
some substring-ing here
etc...
}
}

After couple calls to this method my global string must contain "" since it
has been processed
and all data from it have been extraced by that method and passed to another
methods, since this global var is a buffer....
I expect it to contain nothing but "" empty zero lentgh string, but it
doesn't
Apparently when u manipulate string and Join, Substring Replace etc. in it
it does nothing else bu t GROVING and groving. After a couple of this
operations i converted this string to char array and
displayed it's size. Debugger shows med an empty string , but char array
size wasmore than 1000....
and none of comparison methods (mystring == "") or (mystring.Equals("")
worked :-(

After some close examination i discovered that that char array i converted
my "empty" string to
contains nothing but 0x0 chars :-( HOW CAN IT CONTAIN null chars... ??????

I even tried to pass values through different objects (Huh? why.. dunno)
string ttt = Slices.Substring(Slices.IndexOf("|",0)+1);
Slices = "";
Slices = ttt;

This approach didn't work eighter...

Anyway to solve this and to make my comparison work when buffer string was
"" I had to add
..Replace("\0", "") to every manipulation of my buffer string...

Ex.
Slices = Slices.Substring(Slices.IndexOf("|",0)+1)
Becomes
Slices = Slices.Substring(Slices.IndexOf("|",0)+1).Replace( "\0", "");

Thas seems to solve this problem, but i'm still wondering where this
behavior comes from???
Poor language engineering??? ,, Bug???,,, or am i just stupid?
Nov 15 '05 #1
4 2255
Dim <di****@hotpop.com> wrote:
I found that C# has some buggy ways to process string across methods.
I believe it's actually your understanding which is buggy, not C#.

<snip>
Apparently when u manipulate string and Join, Substring Replace etc. in it
it does nothing else bu t GROVING and groving.
Um, no.
After a couple of this
operations i converted this string to char array and
displayed it's size. Debugger shows med an empty string , but char array
size wasmore than 1000....
and none of comparison methods (mystring == "") or (mystring.Equals("")
worked :-(
No, they wouldn't if your string had loads of null chars in there.
After some close examination i discovered that that char array i converted
my "empty" string to
contains nothing but 0x0 chars :-( HOW CAN IT CONTAIN null chars... ??????
It's a sequence of characters, and character 0 is a valid character.
I even tried to pass values through different objects (Huh? why.. dunno)
string ttt = Slices.Substring(Slices.IndexOf("|",0)+1);
Slices = "";
Slices = ttt;

This approach didn't work eighter...

Anyway to solve this and to make my comparison work when buffer string was
"" I had to add
.Replace("\0", "") to every manipulation of my buffer string...

Ex.
Slices = Slices.Substring(Slices.IndexOf("|",0)+1)
Becomes
Slices = Slices.Substring(Slices.IndexOf("|",0)+1).Replace( "\0", ""); Thas seems to solve this problem, but i'm still wondering where this
behavior comes from???
Poor language engineering??? ,, Bug???,,, or am i just stupid?


It sounds like the strings that you're joining etc (eg Slices) have
some null characters at the end of them. I suggest you find out why,
and decide what you want to do about it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
Dim
No there's nothing wrong with my understanding. i've been programmer for
seven years. I think i can separate illusion from a bug.
I explicitly set ALL of the temporary vars inside the method to "" in the
beginning of the method
Incoming data contains nothing but what i expect it to contain and still
null chars are produced after
each .Substring call.

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Dim <di****@hotpop.com> wrote:
I found that C# has some buggy ways to process string across methods.
I believe it's actually your understanding which is buggy, not C#.

<snip>
Apparently when u manipulate string and Join, Substring Replace etc. in it it does nothing else bu t GROVING and groving.


Um, no.
After a couple of this
operations i converted this string to char array and
displayed it's size. Debugger shows med an empty string , but char array
size wasmore than 1000....
and none of comparison methods (mystring == "") or (mystring.Equals("")
worked :-(


No, they wouldn't if your string had loads of null chars in there.
After some close examination i discovered that that char array i converted my "empty" string to
contains nothing but 0x0 chars :-( HOW CAN IT CONTAIN null chars... ??????
It's a sequence of characters, and character 0 is a valid character.
I even tried to pass values through different objects (Huh? why..

dunno) string ttt = Slices.Substring(Slices.IndexOf("|",0)+1);
Slices = "";
Slices = ttt;

This approach didn't work eighter...

Anyway to solve this and to make my comparison work when buffer string was "" I had to add
.Replace("\0", "") to every manipulation of my buffer string...

Ex.
Slices = Slices.Substring(Slices.IndexOf("|",0)+1)
Becomes
Slices = Slices.Substring(Slices.IndexOf("|",0)+1).Replace( "\0", "");

Thas seems to solve this problem, but i'm still wondering where this
behavior comes from???
Poor language engineering??? ,, Bug???,,, or am i just stupid?


It sounds like the strings that you're joining etc (eg Slices) have
some null characters at the end of them. I suggest you find out why,
and decide what you want to do about it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3
Dim
Btw this is not a question. I already solved it.
It's only to notify all who might have the same problem.

"Dim" <di****@hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I found that C# has some buggy ways to process string across methods.
I have a class with on global string var and a method where i add / remove
from this string
Consider it a buffer... with some values and separators

class
{
private string globalvar = "";

private void manipulate (whattodo ) //substring, join, etc....
{
some manipulation on globalvar...
some join here
some substring-ing here
etc...
}
}

After couple calls to this method my global string must contain "" since it has been processed
and all data from it have been extraced by that method and passed to another methods, since this global var is a buffer....
I expect it to contain nothing but "" empty zero lentgh string, but it
doesn't
Apparently when u manipulate string and Join, Substring Replace etc. in it
it does nothing else bu t GROVING and groving. After a couple of this
operations i converted this string to char array and
displayed it's size. Debugger shows med an empty string , but char array
size wasmore than 1000....
and none of comparison methods (mystring == "") or (mystring.Equals("")
worked :-(

After some close examination i discovered that that char array i converted my "empty" string to
contains nothing but 0x0 chars :-( HOW CAN IT CONTAIN null chars... ??????
I even tried to pass values through different objects (Huh? why.. dunno)
string ttt = Slices.Substring(Slices.IndexOf("|",0)+1);
Slices = "";
Slices = ttt;

This approach didn't work eighter...

Anyway to solve this and to make my comparison work when buffer string was
"" I had to add
.Replace("\0", "") to every manipulation of my buffer string...

Ex.
Slices = Slices.Substring(Slices.IndexOf("|",0)+1)
Becomes
Slices = Slices.Substring(Slices.IndexOf("|",0)+1).Replace( "\0", "");

Thas seems to solve this problem, but i'm still wondering where this
behavior comes from???
Poor language engineering??? ,, Bug???,,, or am i just stupid?

Nov 15 '05 #4
Dim <di****@hotpop.com> wrote:
No there's nothing wrong with my understanding. i've been programmer for
seven years. I think i can separate illusion from a bug.
In that case it's time to demonstrate it.
I explicitly set ALL of the temporary vars inside the method to "" in the
beginning of the method
I don't see what that has to do with it.
Incoming data contains nothing but what i expect it to contain
How exactly are you checking? If you're just doing it by eye in the
debugger, that won't help you as you may not see the null chars.
and still null chars are produced after each .Substring call.


To be honest, I don't believe that. If you're still convinced there's a
bug in the .NET string routines though, you should produce a short but
complete example which demonstrates it. See
http://www.pobox.com/~skeet/csharp/complete.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #5

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

Similar topics

3
by: Dino | last post by:
I am creating a website that is going to ask the user to enter a date! then from an access database get all records where a date field is greater then the date entered! Sounds simple, I do it in...
46
by: yadurajj | last post by:
Hello i am newbie trying to learn C..I need to know about string comparisons in C, without using a library function,...recently I was asked this in an interview..I can write a small program but I...
7
by: Ioannis Vranos | last post by:
I had reported this as a bug: Description: Default indexed property of System::String crashes for object with stack semantics. int main()
10
by: sandorf | last post by:
I'm using the Windows version of Python and IDLE. When I debug my .py file, my modification to the .py file does not seem to take effect unless I restart IDLE. Saving the file and re-importing it...
4
by: VMI | last post by:
How can I split a string that looks like this: John, Doe, 37282, box 2, 10001, "My description, very important", X, Home If I use String.Split(), it'll split the string that's between the...
41
by: Dead Loop | last post by:
Hi all, I'm a beginner and my question is: Are there any differences between char *p = "Hello, world!"; and const char *p = "Hello, world!"; ?
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
14
by: dascandy | last post by:
Hi, I was wondering, is it possible to determine whether a string can be modified (const char *) by the application or whether it's located in what's commonly .rodata? Regards, Peter
41
by: nospam | last post by:
If I have a string say: myvar = "This is a string"; How do I use sprintf to convert the string so it has 4 spaces padded on the left like:
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:
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: 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...
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
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
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.