Posts

Showing posts from November, 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)
{
try
{
DateTime.Parse(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();
SR.Close();
return(sText);
}

reserved device names

Microsoft Windows cannot use these file names (And some of these as folders),
because these are reserved device names(printers,modems etc) or registers:

Here are a few,

CON, PRN, AUX, CLOCK$, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9