Re: StringBuilder Extension: IsQuotedBy

Brady Kelly <[email protected]> Thu, 14 Feb 2008 01:54:03 +0200
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Like I said, I was just playing around and curious.  The real code processes
record definitions, not records, so I doubt any performance hit here would
be measurable without some serious profiling on load.

It's 02h00 here and the mind wanders a bit.

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:[email protected]] On Behalf Of Sebastien
Lambla
Sent: 14 February 2008 01:44 AM
To: [email protected]
Subject: Re: [DOTNET-CLR] StringBuilder Extension: IsQuotedBy

Have you measured any bottleneck in this code? Or in string.startswith ? I
wonder if the temporary allocations in generation 0 are really going to be
worth the effort of asking the question or profiling the answer :)

--
SerialSeb
http://serialseb.blogspot.com


-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:[email protected]] On Behalf Of Brady Kelly
Sent: 13 February 2008 23:33
To: [email protected]
Subject: [DOTNET-CLR] StringBuilder Extension: IsQuotedBy

I was playing around with avoiding, at all costs, creating surplus strings,
and came up with the following method to see if a StringBuilder, that I use
for each of a collection of string fields, is surrounded by a certain
string, e.g. double quotes.  I was just wondering if this is an efficiant
way of doing it:



        public static bool IsQuotedBy(this StringBuilder sb, string
quoteString)

        {

            // Check if the first characters match the quote string.

            for (int i = 0; i < quoteString.Length; i++)

            {

                if (sb[i] != quoteString[i])

                {

                    return false;

                }

            }



            // Check if the last characters match the quote string.

            for (int i = sb.Length - quoteString.Length; i < sb.Length; i++
)

            {

                int qsIndex = 0;

                if (sb[i] != quoteString[qsIndex++])

                {

                    return false;

                }

            }



            return true;

        }


===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com