Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
FILE HOSTS PREMIUM ACCOUNT
ALL FILE HOST PREMIUM ACCOUNTS
Zynga Slingo Trainer v5.12
iTunes Gift Card Generator V3.1 2012
Diablo 3 GOLD Coins FREE
Working PS3 Jailbreak 3.65 And 3.66
ExtaBit Premium Accounts and Cookies
Steam Wallet Hack - Money Adder & Hack v3
Empires & Allies Hack Cheat Trainer v5.4.1
Eve Onnline 60 Days Time Card Generator v2
Popular
XBOX POINTS GENERATOR - MICROSOFT POINTS GENERATOR v1.2012
11 may 2012 premium uploading accounts 100% working
Free Microsoft Points
Free Microsoft Points - Microsoft Points Generator - Xbox Live Codes 2012
Car Town Free Blue Points Hack
Free CarTown Blue Points Generator and CarTown Templates
Better way to get content via jQuery $.get()
Free Microsoft Points
Simple Days Purger
Sharecash Downloader Bypass Surveys New 05/2012
Pastable version of
StringExt.cs (String Extension)
<pre class='prettyprint' language='cs'>namespace Utilities { using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; public static class StringExt { public static bool IsEmail(this string inputstr) { // exit if the string is null or empty if (inputstr.IsEmpty()) return false; string strRegex = @"^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; return inputstr.MatchRegex(strRegex); } public static bool IsZip(this string inputstr) { // exit if the string is null or empty if (inputstr.IsEmpty()) return false; string strRegex = @"^\d{5}$|^\d{5}-\d{4}$"; return inputstr.MatchRegex(strRegex); } public static bool IsStateAbbrv(this string inputstr) { return inputstr.IsStateAbbrv(false); } public static bool IsStateAbbrv(this string inputstr, bool CaseSensitive) { // exit if the string is null or empty if (inputstr.IsEmpty()) return false; string strRegex = @"^((AL)|(AK)|(AS)|(AZ)|(AR)|(CA)|(CO)|(CT)|(DE)|(DC)|(FM)|(FL)|" + @"(GA)|(GU)|(HI)|(ID)|(IL)|(IN)|(IA)|(KS)|(KY)|(LA)|(ME)|(MH)|(MD)|(MA)|(MI)|" + @"(MN)|(MS)|(MO)|(MT)|(NE)|(NV)|(NH)|(NJ)|(NM)|(NY)|(NC)|(ND)|(MP)|(OH)|(OK)|" + @"(OR)|(PW)|(PA)|(PR)|(RI)|(SC)|(SD)|(TN)|(TX)|(UT)|(VT)|(VI)|(VA)|(WA)|(WV)|" + @"(WI)|(WY))$"; return inputstr.MatchRegex(strRegex, CaseSensitive); } public static bool IsStateName(this string inputstr) { return inputstr.IsStateName(false); } public static bool IsStateName(this string inputstr, bool CaseSensitive) { // exit if the string is null or empty if (inputstr.IsEmpty()) return false; string strRegex = @"^((Alabama)|(Alaska)|(AmericanSamoa)|(Arizona)|(Arkansas)|(California)|" + @"(Colorado)|(Connecticut)|(Delaware)|(DistrictofColumbia)|(Florida)|(Georgia)|(Guam)|" + @"(Hawaii)|(Idaho)|(Illinois)|(Indiana)|(Iowa)|(Kansas)|(Kentucky)|(Louisiana)|(Maine)|" + @"(Maryland)|(Massachusetts)|(Michigan)|(Minnesota)|(Mississippi)|(Missouri)|(Montana)|" + @"(Nebraska)|(Nevada)|(NewHampshire)|(NewJersey)|(NewMexico)|(NewYork)|(NorthCarolina)|" + @"(NorthDakota)|(NorthernMarianasIslands)|(Ohio)|(Oklahoma)|(Oregon)|(Pennsylvania)|" + @"(PuertoRico)|(RhodeIsland)|(SouthCarolina)|(SouthDakota)|(Tennessee)|(Texas)|(Utah)|" + @"(Vermont)|(Virginia)|(VirginIslands)|(Washington)|(WestVirginia)|(Wisconsin)|(Wyoming))$"; return inputstr.MatchRegex(strRegex, CaseSensitive); } public static bool IsEmpty(this string inputstr) { if (inputstr == null || inputstr.Trim().Length == 0) { return true; } return false; } public static bool IsPhone(this string inputstr) { // exit if the string is null or empty if (inputstr.IsEmpty()) return false; string strRegex = @"^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$"; return inputstr.MatchRegex(strRegex); } public static bool MatchRegex(this string inputstr, string regex) { return inputstr.MatchRegex(regex, false); } public static bool MatchRegex(this string inputstr, string regex, bool CaseSensitive) { var IsCaseSensitive = RegexOptions.IgnoreCase; if (CaseSensitive) { IsCaseSensitive = RegexOptions.None; } return System.Text.RegularExpressions.Regex.IsMatch(inputstr, regex, IsCaseSensitive); } public static bool EqualsIgnoreCase(this string s, string value) { return s.ToLowerInvariant() == value.ToLowerInvariant(); } // be nice to VB & CF devlopers public static string Left(this string s, int position) { return s.Substring(0, position); } // be nice to VB & CF devlopers public static string Right(this string s, int position) { return s.Substring(s.Length - position); } public static string Reverse(this string s) { char[] charArray = s.ToCharArray(); Array.Reverse(charArray); return new string(charArray); } public static string FormatTitleCase(this string s) { string[] words = s.Split(' '); string result = string.Empty; string temp = string.Empty; foreach (string i in words) { temp = i.ToLower(); result = result + i.Substring(0, 1).ToUpper() + i.Substring(1) + " "; } result = result.Substring(0, result.Length - 1); return result; } /// <summary> /// convert a string that is CSV formated into a List /// credit goes to www.usualdosage.com where I got most of this code /// </summary> /// <param name="s"></param> /// <returns>List</returns> public static List<string> CSVToList(this string s) { char CHAR_COMMA = Convert.ToChar(44); char CHAR_QUOTE = Convert.ToChar(34); char CHAR_PIPE = Convert.ToChar(124); char CHAR_BACKQUOTE = Convert.ToChar(96); // Create a new array to contain the return values string strCurrent = s; string[] arrTokens = null; // Replace any instance of double quotes with a back quote strCurrent = strCurrent.Replace("\"\"", "`"); if (!strCurrent.Contains(CHAR_QUOTE.ToString())) // No quotes, so just split on commas { arrTokens = strCurrent.Split(CHAR_COMMA); } else // Contains quotes, so more detailed parsing needed { bool bQuote = false; bool bEscape = false; // Convert temp to a char array to make it easier to check each char char[] arrTempChars = strCurrent.ToCharArray(); for (int i = 0; i < arrTempChars.Length; i++) { // Loop through until we find a quote. If found, flip the bool value if (arrTempChars[i] == CHAR_QUOTE) { if (!bEscape) bQuote = !bQuote; } // If we’re in a quote group and find a comma, change it to a temp char for the moment if (bQuote && (arrTempChars[i] == CHAR_COMMA)) { arrTempChars[i] = CHAR_PIPE; } } // Parse out the modified character array into a string string strReassemble = string.Empty; for (int j = 0; j < arrTempChars.Length; j++) { strReassemble = strReassemble + arrTempChars[j].ToString(); } // Remove the quotes, which will leave just commas, and split strReassemble = strReassemble.Replace(CHAR_QUOTE.ToString(), string.Empty); arrTokens = strReassemble.Split(CHAR_COMMA); // Loop through the array, and reset the temp chars back to // commas, and replace the back quotes with double quotes for (int k = 0; k < arrTokens.Length; k++) { arrTokens[k] = arrTokens[k].Replace(CHAR_PIPE, CHAR_COMMA); arrTokens[k] = arrTokens[k].Replace(CHAR_BACKQUOTE, CHAR_QUOTE); } } List<string> rtrnList = new List<string>(); foreach (string entry in arrTokens) { rtrnList.Add(entry); } return rtrnList; } /// <summary> /// convert a string that is CSV formated into a List /// credit goes to www.usualdosage.com where I got most of this code /// </summary> /// <param name="s"></param> /// <returns>List</returns> public static string[] CSVToArray(this string s) { return s.CSVToList().ToArray(); } /// <summary> /// Convert a string[] into a single string that is seperated by a /// delimiter /// </summary> /// <param name="s"></param> /// <returns></returns> public static string ToDelimitedString(this string[] s) { return s.ToDelimitedString(",", false); } public static string ToDelimitedString(this string[] s, string vDelimeter) { return s.ToDelimitedString(vDelimeter, false); } public static string ToDelimitedString(this string[] s, bool QuoteEachEntry) { return s.ToDelimitedString(",", QuoteEachEntry); } public static string ToDelimitedString(this string[] s, string Delimeter, bool QuoteEachEntry) { string result = string.Empty; string vDelim = string.Empty; foreach (string element in s) { if(QuoteEachEntry) result += vDelim + "\"" + element + "\""; else result += vDelim + element; vDelim = Delimeter; } return result; } } }</pre> <a href="http://www.refactormycode.com/codes/422-stringext-cs-string-extension" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>