using System;
public class TestConsoleApp {
public static void Main(string[] args) {
string s = string.Format("123");
string t = string.Format("{0}", 123);
string u = string.Format("{0:D3}", 123);
Console.WriteLine(s);
Console.WriteLine(t);
Console.WriteLine(u);
}
}
ASP.NET & Csharp (C#)
ASP.NET & Csharp (C#) , Here you can find my posts about .NET c# .
Format a string
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
int theInt = 90;
double theDouble = 9.99;
bool theBool = true;
Console.WriteLine("Int is: {0}
Double is: {1}
Bool is: {2}",theInt, theDouble, theBool);
}
}
Fill placeholders using an array of objects.
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
object[] stuff = { "Hello", 20.9, 1, "There", "83", 99.99933 };
Console.WriteLine("The Stuff: {0} , {1} , {2} , {3} , {4} , {5} ", stuff);
Console.WriteLine("{0}, Number{0}, Number{0}", 9);
}
}
Use the static String.Format() method to build a new string.
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string formatStr;
formatStr = String.Format("Don't you wish you had {0:C} in your account?", 99989.987);
Console.WriteLine(formatStr);
}
}
use the Format() method to format a string
using System;
class MainClass {
public static void Main() {
float myFloat = 1234.56789f;
string myString8 = String.Format("{0, 10:f3}", myFloat);
Console.WriteLine("String.Format("{0, 10:f3}", myFloat) = " + myString8);
}
}
Compare two strings with StringComparison.CurrentCultureIgnoreCase
using System;
public static class StringExtensions
{
public static bool EqualsIgnoreCase(this string me, string them)
{
return me.Equals(them, StringComparison.CurrentCultureIgnoreCase);
}
}
Check if a String contain another string by ignoring case
using System;
public static class StringExtensions
{
public static bool ContainsIgnoreCase(this string me, string other)
{
return me.ToLower().Contains(other.ToLower());
}
}