I got my google notebook on my doorstep last night. I'll write a review over the weekend.

posted by dharh 4:49 PM Dec 10th, 2010

10. Create files with date and time stamp appended to the name

Note: Windows does not like ':' in file names. Also I made this extension friendly so it doesn't just add a date time stamp at the end of an html file for example and instead puts the stamp just before the '.'

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace lrn2CSharp10 { class Program { static void Main( string[ ] args ) { string fileName = ""; string timestamp = DateTime.Now.ToString( "MM-dd-yyyy_HH-mm-ss" ); Console.WriteLine( "Input name of new file in the current directory to create (it will have the current date appended to it)." ); Console.Write( ":" ); try { fileName = Console.ReadLine( ); if ( fileName.Contains( '.' ) ) { string scope = fileName.Split( '.' ).Last( ).ToLower( ); fileName = fileName.Replace( "." + scope, "_" + timestamp + "." + scope ); } else { fileName += "_" + timestamp; } FileStream fs = new FileStream( fileName, FileMode.Create ); fs.Close( ); } catch { Console.WriteLine( "WTF?!?" ); } } } }

posted by dharh 3:20 PM Sep 30th, 2010

9. Time and Date : Get system time and convert it in different formats 'DD-MON-YYYY', 'mm-dd-yyyy', 'dd/mm/yy' etc. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace lrn2csharp9 { class Program { static void Main( string[ ] args ) { DateTime now = DateTime.Now; Console.WriteLine( "Today's date is: " + now.ToString( "MMM dd yyyy HH:mm:ss" ) ); Console.WriteLine( "Also: " + now.ToString( "dd-MMM-yyyy" ) ); Console.WriteLine( "And: " + now.ToString( "MM-d-yyyy" ) ); Console.WriteLine( "One more thing: " + now.ToString( "d/MM/yy" ) ); } } }

posted by dharh 3:03 PM Sep 30th, 2010

I have been working hard on a .NET project for work and thus have not had the energy to do any other work. The project is nearing a major milestone in the next few months which should means I should be less stressed. Which means I can start working on IDT related stuff. So, stay tuned or something.

posted by dharh 12:47 PM Jul 20th, 2010

8. Open a text file and convert it into HTML file. (File operations/Strings) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace lrn2csharp8 { class Program { static void Main( string[ ] args ) { string file = ""; string html = "<html><head><title></title></head><body>{0}</body></htm>"; string textFile = ""; Console.WriteLine( "Input name of a file in the current directory to convert into an HTML document." ); Console.Write( ":" ); try { file = Console.ReadLine( ); FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Read ); StreamReader sr = new StreamReader( fs ); while(!sr.EndOfStream) { string line = sr.ReadLine( ); if ( line.Length != 0 ) textFile += "<p>" + line + "</p>"; } sr.Close( ); StreamWriter sw = new StreamWriter( fs.Name + ".html" ); sw.Write( string.Format( html, textFile ) ); sw.Close( ); fs.Close( ); } catch ( Exception e ) { Console.WriteLine( "WTF?!?" ); } } } }

posted by dharh 2:14 AM Jan 30th, 2010

Chrome Extensions are here! Since Chrome became my main browser there's one thing I've missed the most and thats the extensive extension library on Firefox. Now that we finally have extensions here's a short list of the ones I am using so far:

That's it for now. I'll add more as I find good ones.


posted by dharh 2:40 PM Dec 8th, 2009

7. Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace lrn2CSharp7 { class Program { static void Main( string[ ] args ) { double theNumber; Console.WriteLine( "Input a number to be formatted" ); Console.Write( ":" ); try { theNumber = Convert.ToDouble( Console.ReadLine( ) ); Console.WriteLine( "Original number: {0}", theNumber ); Console.WriteLine( "Rounded up to the 5th decimal place: {0}", Math.Round( theNumber, 5 ) ); Console.WriteLine( "Truncating after the 4th decimal place: {0}", Decimal.Truncate( Convert.ToDecimal( theNumber * 10000 ) ) / 10000 ); Console.WriteLine( "Padding 7 zeroes on each side: {0}", String.Format( "{0:0000000.0000000}", theNumber ) ); Console.WriteLine( "Here is a box with 20 spaces: | |" ); Console.WriteLine( "Here is the number left justified: |{0,-20}|", theNumber ); Console.WriteLine( "Here is the number right justified: |{0,20}|", theNumber ); } catch ( FormatException fe ) { Console.WriteLine( "You did not enter a valid number fool." ); } Console.WriteLine( "Press esc to exit." ); while ( !keyPressHandler( Console.ReadKey( true ) ) ) { Thread.Sleep( 250 ); /* no op */ } } protected static Boolean keyPressHandler( ConsoleKeyInfo input ) { if ( input.Key == ConsoleKey.Escape ) return true; return false; } } }

posted by dharh 9:56 PM Dec 5th, 2009


« Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Next »

2024: 1
2023: 4 2 1
2022: 5 3
2011: 5 3 1
2010: 12 9 7 1
2009: 12 11 8 5
2008: 12 5 4 3 2 1
2007: 12 11 10 9 8 7 6 5 4 3 2 1
2006: 12 11 10 9 8 7 6 5 4 3 2 1
2005: 12 10 7 6
2004: 10 9 6 5 4 3 2 1