November 21, 2005

Some Useful Functions

1. convert a string to Proper Case

public static string ConvertToProperCase(string text)
System.Globalization.TextInfo TI = new System.Globalization.CultureInfo("en-US",false).TextInfo;
return TI.ToTitleCase(text);

eg: "rOshaN punnIlaTH mOHAmmed" --> "Roshan Punnilath Mohammed"

2. To validate that a string is a valid date

public static bool IsDate(string text)
return true;
catch { return false; }

3. To remove HTMl tags from a string

public static string RemoveHTML(string desc)
return Regex.Replace(desc,@"<(.\n)*?>", string.Empty);

4. To read a file

public static string ReadFile(string sFile)
StreamReader SR;
string sText;
SR = File.OpenText(sFile);
sText = SR.ReadToEnd();

No comments:

Post a Comment