How to use C# string Format

How to use C# string Format

string Format method replace the argument Object into a text equivalent System.String.

Replace string Particular index for ex System.String.Format("Hi welcome Mr {0}","Sutahahr")

System.String.format(string format,Object arg0)

Parameters:

String format : The format String

The format String Syntax is like {indexNumber:formatCharacter}

Object arg0 : The object to be formatted.

Returns:

String : The formatted String

Examples :

Currency :

String.Format("{0:c}", 10) will return $10.00
The currency symbol ($) displayed depends on the global locale settings.

Date :

String.Format("Today's date is {0:D}", DateTime.Now)

You will get Today's date like : 01 January 2005

Time :

String.Format("The current time is {0:T}", DateTime.Now)

You will get Current Time Like : 10:10:12
--
J.SuThahar MCA

MicroSoft Technology Specialist

Microsoft Certified ProfessionalDeveloper

www.jsuthahar.tk

09943151415

0 Comments

Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts