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

Re: string.Trim() behavior

Kevin Smith <no@spam.comwrites:
According to the intellisense help, string.Trim() "Removes all occurances
or white space characters from the beginning and end of this instance."
[snip]

You posted this to microsoft.public.dotnet.languages.csharp, where I
presume it's topical. Why on Earth did you redirect followups to
comp.lang.c?

Anyone else replying to Kevin Smith's article, please *ignore* the
Followup-To header and post only to the csharp group. Thanks.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 8 '08 #1
8 3219
Hi

I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the more
common comp.lang.c group.

Best

KS
On Wed, 08 Oct 2008 12:25:54 -0700, Keith Thompson wrote:
Kevin Smith <no@spam.comwrites:
>According to the intellisense help, string.Trim() "Removes all occurances
or white space characters from the beginning and end of this instance."
[snip]

You posted this to microsoft.public.dotnet.languages.csharp, where I
presume it's topical. Why on Earth did you redirect followups to
comp.lang.c?

Anyone else replying to Kevin Smith's article, please *ignore* the
Followup-To header and post only to the csharp group. Thanks.
Oct 8 '08 #2
Kevin Smith wrote:
Hi

I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the more
common comp.lang.c group.
That excuse reminds me of the drunk who looks for his keys near the
light pole, even though he lost them in the woods, because the light
pole has better lighting. You'll find this strategy equally
counterproductive.
Oct 8 '08 #3
On 8 Oct 2008 at 20:01, Kevin Smith wrote:
I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the
more common comp.lang.c group.
That sounds perfectly reasonable.

As I understand it, C# is a language derived from C, so it is just about
topical here.

Oct 8 '08 #4
In article <sl*******************@nospam.invalid>,
Antoninus Twink <no****@nospam.invalidwrote:
>On 8 Oct 2008 at 20:01, Kevin Smith wrote:
>I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the
more common comp.lang.c group.

That sounds perfectly reasonable.

As I understand it, C# is a language derived from C, so it is just about
topical here.
Fasten your safety belts and enjoy the ride...

Oct 8 '08 #5
In article <57**********************************@y29g2000hsf. googlegroups.com>,
<ja*********@verizon.netwrote:
>Kevin Smith wrote:
>Hi

I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the more
common comp.lang.c group.

That excuse reminds me of the drunk who looks for his keys near the
light pole, even though he lost them in the woods, because the light
pole has better lighting. You'll find this strategy equally
counterproductive.
Certainly here, that's true.

If I had the time, I'd come up with a typically stupid CLC-type
counter-analogy to your typically stupid CLC-type analogy.

Oct 8 '08 #6
Kevin Smith wrote, On 08/10/08 21:01:
Hi

I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the more
common comp.lang.c group.
Why do you think it is appropriate to direct posts about c# to
comp.lang.c? C is a completely different language and C# IS NOT TOPICAL.

If your house is closer to a customer I'm visiting should I just barge
in to your house and stay? After all it is more convenient than staying
at home or paying for a hotel.

Please keep your C# somewhere it is topical. Also keep your top-posting
where it is acceptable, which is not here.

<snip>
>Anyone else replying to Kevin Smith's article, please *ignore* the
Followup-To header and post only to the csharp group. Thanks.
Please everyone keep the responses about csharp on the csharp group as
Kevin requested.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Oct 8 '08 #7
[Piggy-backing - followups set to comp.lang.c]

Keith Thompson said:
Kevin Smith <no@spam.comwrites:
>According to the intellisense help, string.Trim() "Removes all
occurances or white space characters from the beginning and end of this
instance."
[snip]

You posted this to microsoft.public.dotnet.languages.csharp, where I
presume it's topical. Why on Earth did you redirect followups to
comp.lang.c?

Anyone else replying to Kevin Smith's article, please *ignore* the
Followup-To header and post only to the csharp group. Thanks.
Sorry, Keith, but my reply is C-relevant as well as C#-relevant.

(Incidentally, I'm piggybacking because my newsreader didn't see the
article in the normal feed, but I'm able to comment on the article because
my newsreader *could* find the article on an ID search - go figure,
because I can't.)

The question is:

"the follow code does not appear to modify s.

s.Trim('\r');

While the follow code DOES modify s.

s = s.Trim(\r');

If this is modifying this instance, why do I only get the effect if I
assign the result?"

And the answer is simple to deduce, but quite difficult to frame in a way
that is relevant in both cross-posted groups. Nevertheless, I intend to
try.

Operations take inputs and produce results. Very often, those operations do
not modify their inputs - and this is a Good Thing. If the subtraction
operator modified its input, we'd be furious: x = 6 - 2; would change 6
into 4, so printf("%d\n", 6) would produce 4 from now on!

Your code: s.Trim('\r'); is roughly analogous to x - 2. That is, if you
were to write this:

x - 2;

you would expect the code to do nothing. (You might even expect it to
result in a compilation error but, if so, you would be disappointed.)

But if you were to write this:

x = x - 2;

you would have every right to expect that x's value would be updated.

Now, C isn't C#, but it's not beyond the wit of mankind to imagine a C
variant in which strings are genuine first-class objects rather than mere
arrays of char. In such a language, one might reasonably implement a trim
function in a manner such as this:

string trim(string in)
{
string out = "";
size_t i = 0;
size_t j = in.length;
while(i < in.length && isspace(in.str[i]))
{
++i;
}
while(j 0 && isspace(in.str[j - 1]))
{
--j;
}
while(i < j)
{
out.append(in.str[i++]);
}
return out;
}

(Okay, so this isn't exactly legal C, but it wouldn't take much to make it
so.) The point is that this function accepts an input which it does not
modify - it creates a new object whose value it returns on completion. And
that's what your C# Trim function is doing, and that's why you have to say
s = s.Trim('\r').

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 9 '08 #8
Antoninus Twink <no****@nospam.invalidwrote:
On 8 Oct 2008 at 20:01, Kevin Smith wrote:
I want to be able to read answers at work which doesnt take
microsoft.public.dotnet.languages.csharp, so I put followups to the
more common comp.lang.c group.

That sounds perfectly reasonable.

As I understand it, C# is a language derived from C,
You understand wrong...
so it is just about topical here.
....and you lie about topicality, as usual.

Richard
Oct 9 '08 #9

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

Similar topics

4
by: knocker | last post by:
Hi I have a problem with JSP on websphere 5. When I try save information with swedish or danish ÅÄÖ characters, the string is cut where the first of these characters occurs. The JDK used is...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
13
by: Jonathan Wood | last post by:
According to the intellisense help, string.Trim() "Removes all occurances or white space characters from the beginning and end of this instance." However, the follow code does not appear to...
22
by: Terry Olsen | last post by:
I have an app that makes decisions based on string content. I need to make sure that a string does not contain only spaces or newlines. I am using the syntax 'Trim(String)" and it works fine. I...
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...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
121
by: swengineer001 | last post by:
Just looking for a few eyes on this code other than my own. void TrimCString(char *str) { // Trim whitespace from beginning: size_t i = 0; size_t j; while(isspace(str)) {
8
by: Kevin Smith | last post by:
Hi, According to the intellisense help, string.Trim() "Removes all occurances or white space characters from the beginning and end of this instance." However, the follow code does not appear...
2
by: Peter Duniho | last post by:
On Wed, 08 Oct 2008 11:26:01 -0700, Kevin Smith <no@spam.comwrote: No, it wouldn't. Nor would it modify the String instance that s refers to. Strings are immutable. They are _never_...
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
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 project—planning, coding, testing,...

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.