Re: StringBuilder Extension: IsQuotedBy
Shawn Wildermuth <[email protected]> Wed, 13 Feb 2008 19:02:12 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
I think there is too much whitespace in the code...you're wasting Carriage Returns in your code formatting... ;) Thanks, Shawn Wildermuth http://adoguy.com http://wildermuthconsulting.com Microsoft MVP (C#), MCSD.NET, Author and Speaker The Silverlight Tour is coming to a city near you! -----Original Message----- From: Discussion of development on the .NET platform using any managed language [mailto:[email protected]] On Behalf Of Peter Obiefuna Sent: Wednesday, February 13, 2008 6:57 PM To: [email protected] Subject: Re: [DOTNET-CLR] StringBuilder Extension: IsQuotedBy Brad, This algorithm looks inexpensive enough to me. But I think that whitespace padding (or non-printables) may mask the result. For that reason, I would prefer a RegularExpression.Match. P -------------------------------------------------- From: "Brady Kelly" <[email protected]> Sent: Wednesday, February 13, 2008 4:33 PM 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 DevelopMentorR http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentorR 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