Showing posts with label Sting Manupulation. Show all posts
Showing posts with label Sting Manupulation. Show all posts

Wednesday, September 1, 2010

How to add comma in a int or decimal value

This code show how to add comma into int or decimal value.Suppose we have a value 33000
and want to display this 33,000.00.

string FirstP = "";
string SecP = "";
string Finalstr = "";
int MyValue = Convert.ToInt32(Projected);
string myStr = MyValue.ToString();
int Length = myStr.Length;
string dc = ".00";

do
{
FirstP = myStr.Substring(0, Length - 3);
SecP = myStr.Substring(Length - 3, 3);
Finalstr = "," + SecP + Finalstr;
myStr = FirstP;
Length = myStr.Length;
}
while (Length > 3);

if (myStr == "")
{
Finalstr = Finalstr.Substring(1, Finalstr.Length);
}
else
{
Finalstr = myStr + Finalstr + dc;
}

lblSalary.Text = Finalstr.ToString();

Sunday, August 29, 2010

String Manupulation

i have a string like "a,b,c. upto n values"..
Show this string like
a,
b,
C

Sol
string str = "a,b,c";
string[] arr = str.Split(',');
foreach (string s in arr)
{
Response.Write(s + ",
");
}