| |
|
posted by Tihomir Ivanov on 02 January 2010 13:37
Sometimes you may have strings to represent dates (ex. 20100102 that represents 2010 January 2), here's an example how it can be converted to DateTime:
string dtString = "20100102";
IFormatProvider culture = new CultureInfo("en-EN", false);
DateTime dt = DateTime.ParseExact(dtString, "yyyyMMdd", culture, DateTimeStyles.NoCurrentDateDefault);
Now, if you want to convert DateTime variable to string in the format above, here's an example how it can be done:
String dtNewString = String.Format("{0:dd/MM/yyyy}", dt);
|
|
posted by Tihomir Ivanov on 24 November 2009 16:13
Here's a simple example how you can detect URLs in some text and replace them with html code for hyperlinks:
string someText = "here's a simple text that contains urls in it like http://www.aspnetsource.com or http://aspnetsource.com or http://aspnetsource.com";
// we create a Regex object with pattern to detect URLs
Regex reg = new Regex(@"((http|https|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))*[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
string htmText = reg.Replace(someText, "<a href=\"$1\">$1</a>");
/* now htmlText contains formatted html code with hrefs:
here's a simple text that contains urls in it like <a href="http://www.aspnetsource.com">http://www.aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a> or <a href="http://aspnetsource.com">http://aspnetsource.com</a>
*/
|
|
posted by Tihomir Ivanov on 23 April 2009 10:21
In my work I had to concatenate two byte arrays but,
unfortunately, it seems that there's no elegant way to do
concat of two byte arrays in "C#" :(
I'd offer you a suggestion for doing it,
just copy-paste this simpe function in your project:
|
|