The text of this article is not in this database — only its details are. Read it on the old site: Custom String Methods using C#
3 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Custom String Methods using C#
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
james.curranPosted Feb 1, 2010, 2:49 PM
This one's only slightly faster public static int CharCount2(String strSource, String strToCount) { int iCount = 0; int iPos = strSource.IndexOf(strToCount); while (iPos != -1) { iCount++; iPos = strSource.IndexOf(strToCount, iPos+1); } return iCount; }
james.curranPosted Feb 1, 2010, 2:43 PM
public static String Reverse2(String strParam) { byte[] rev = Encoding.ASCII.GetBytes(strParam); Array.Reverse(rev); return Encoding.ASCII.GetString(rev); }
james.curranPosted Feb 1, 2010, 2:36 PM
Sorry if this is a repeat... I'm not sure if the first comment made it.... Besides being simpler & easier to understand, this is sgnificantly faster: public static String PCase2(String strParam) { StringBuilder sb = new StringBuilder(strParam.Length); char cPrev = '.'; // start with something to force the next character to upper. foreach(char c in strParam) { if (cPrev == '.' || Char.IsWhiteSpace(cPrev)) sb.Append(Char.ToUpper(c)); else sb.Append(Char.ToLower(c)); cPrev = c; } return sb.ToString(); }