CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of format
C#
static void Main(string[] args)
{
    Console.WriteLine(PhoneNumber("12345678901234"));
    Console.WriteLine(PhoneNumber("1234567890123"));
    Console.WriteLine(PhoneNumber("123456789012"));
    Console.WriteLine(PhoneNumber("12345678901"));
    Console.WriteLine(PhoneNumber("1234567890"));
    Console.WriteLine(PhoneNumber("123456789"));
    Console.WriteLine(PhoneNumber("12345678"));
    Console.WriteLine(PhoneNumber("1234567"));
by Jerry Nixon   December 06, 2011 @ 8:10am
Tags: C#, Format
71 Views
no comments
 
C#
string strFormatedGuid = Guid.NewGuid().ToString("N"); //Where N is the format, can be any of the ones described below
 
/*
Format: N
Output 32 digits:
00000000000000000000000000000000
 
Format: D
Output 32 digits separated by hyphens:
00000000-0000-0000-0000-000000000000
by Egli   August 02, 2011 @ 8:14pm
70 Views
no comments
 
C#
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
 
String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
by Egli   July 24, 2011 @ 10:54pm
69 Views
no comments
 
C#
// Just two decimal places
String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 123.4);         // "123.40"
String.Format("{0:0.00}", 123.0);         // "123.00"
 
// Max. two decimal places
String.Format("{0:0.##}", 123.4567);      // "123.46"
String.Format("{0:0.##}", 123.4);         // "123.4"
String.Format("{0:0.##}", 123.0);         // "123"
by Egli   July 24, 2011 @ 10:51pm
71 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using FizzWare.NBuilder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
 
namespace Tests.Reporting
{
    [TestClass]
    public class DynamicXmlFormatting
128 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using FizzWare.NBuilder;
using Microsoft.VisualStudio.TestTools.UnitTesting;
 
namespace Tests.Reporting
{
    [TestClass]
    public class DynamicTextFormatting
    {
137 Views
no comments
 
SQL
select * from INFORMATION_SCHEMA.COLUMNS where table_name not like 'v%' order by TABLE_NAME, ORDINAL_POSITION
 
select * from INFORMATION_SCHEMA.ROUTINES
 
select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
 
SELECT s.name [SPECIFIC_SCHEMA], o.name [SPECIFIC_NAME], s.name [ROUTINE_SCHEMA], o.name [ROUTINE_NAME], 
case when o.[type] in ('P', 'PC') then 'PROCEDURE' 
when o.type in ('V') then 'VIEW' 
by Thom Lamb   June 13, 2011 @ 8:10am
80 Views
no comments
 
C#
int intValue = 1512;
string stringValue = intValue.ToString("#,#", CultureInfo.GetCultureInfo(Thread.CurrentThread.CurrentCulture.Name));
/* Result in US English (en-US) will be 1,512
   Result in Swedish (sv-SE) will be 1 512 */
by Robert Andersson   April 29, 2010 @ 4:53am
298 Views
no comments
 
C#
public static class HenriFormatter
{
  private static string OutExpression(object source, string expression)
  {
    string format = "";
 
    int colonIndex = expression.IndexOf(':');
    if (colonIndex > 0)
    {
      format = expression.Substring(colonIndex + 1);
by Martin Larsen   January 08, 2010 @ 1:51am
176 Views
no comments
 
// get from 
// http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_20759950.html
 
function fixedLengthNumber(num, size) {
    var str = num.toString();
    var l = size - str.length;
    for (i = 0; i < l; i++) {
        str = "0" + str;
    }
    return str;
by tiago.deliberali   January 05, 2010 @ 7:44am
293 Views
no comments
 
C#
/// <summary>
/// Allows setting of a value in a UrlEncoded string. If the key doesn't exist
/// a new one is set, if it exists it's replaced with the new value.
/// </summary>
/// <param name="urlEncoded">A UrlEncoded string of key value pairs</param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string SetUrlEncodedKey(string urlEncoded, string key, string value)
{
by Rick Strahl   November 30, 2009 @ 4:07pm
563 Views
no comments
 
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Threading;
using System.Globalization;
by jwwishart   November 12, 2009 @ 7:04pm
387 Views
no comments
 
C#
// 2010-10-12: Code has moved to http://bitbucket.org/jonsagara/extensionmethods/
by Jon Sagara   November 02, 2009 @ 1:20pm
268 Views
no comments
 
C#
public static string LOSSerializeObject(object obj)
{
    System.Web.UI.LosFormatter output = new System.Web.UI.LosFormatter();
    StringWriter writer = new StringWriter();
    output.Serialize(writer, obj);
    return writer.ToString();
}
 
public static object LOSDeserializeObject(string inputString)
{
by jrt   September 18, 2009 @ 6:00pm
382 Views
no comments
 
C#
public static string KeyToString(object itemKey)
{
using (TextWriter writer = new StringWriter())
{
LosFormatter formatter = new LosFormatter();
formatter.Serialize(writer, itemKey);
return HttpUtility.UrlEncode(writer.ToString());
}
}
by jrt   September 18, 2009 @ 5:58pm
240 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate