473,322 Members | 1,401 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,322 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 3216
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.