473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: string.Trim() behavior

Kevin Smith <no@spam.comwri tes:
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.publi c.dotnet.langua ges.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_Keit h) 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 3254
Hi

I want to be able to read answers at work which doesnt take
microsoft.publi c.dotnet.langua ges.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.comwri tes:
>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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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
counterproducti ve.
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.publi c.dotnet.langua ges.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.publ ic.dotnet.langu ages.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************ *************** *******@y29g200 0hsf.googlegrou ps.com>,
<ja*********@ve rizon.netwrote:
>Kevin Smith wrote:
>Hi

I want to be able to read answers at work which doesnt take
microsoft.publ ic.dotnet.langu ages.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
counterproduct ive.
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.publi c.dotnet.langua ges.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.cause way.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.comwri tes:
>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.publi c.dotnet.langua ges.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.s tr[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.publi c.dotnet.langua ges.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
11644
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 1.3.1 I've tried: String CUNM = request.getParameter("CUNM").trim(); CUNM = URLDecoder.decode(CUNM,"UTF-8");
11
5352
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 (strIn.Substring(410, 10).Trim = "") Then 'Something processed Else 'Something processed
13
2640
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 modify s. s.Trim('\r'); While the follow code DOES modify s. s = s.Trim(\r');
22
9745
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 thought I'd change it to the VB ..NET method "String.Trim" but that throws an object exception. Which brings the question: is it compliant to use Trim(String), or is it more within etiquette to use If Not String Is Nothing Then String.Trim?
26
3810
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 test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
1
6065
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 during the runtime, the user can click on a button and change the connection string without exiting the application. I would really appreciate any sort of help.
121
5120
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
2839
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 to modify s. s.Trim('\r'); While the follow code DOES modify s.
2
698
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_ modified, by any method. Yes, the variable s is modified, so that it refers to a new instance of the string with the whitespace removed. The original instance is not modified.
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.