AidaHagh / C-Sharp

Learn C#
1 stars 0 forks source link

String -String Format - String Builder #4

Open AidaHagh opened 2 months ago

AidaHagh commented 2 months ago

در string برای value میتوانیم با استفاده از بعضی حروف و علامت ها تغییراتی ایجاد کنیم مثلا با قرار دادن n/ بین دو کلمه باعث میشه سطر ایجاد بشه و دو کلمه هرکدام در سطر جداگانه قرار بگیرند. t/ باعث ایجاد فاصله به اندازه یک تب( tab) میشود. b/ پررنگ (bold)میکنه و....

AidaHagh commented 2 months ago

string name = " red \" blue\" yellow "; // red "blue" yellow string path1=@"D:\User\Project"; //D:\User\Proj string path2="D:\User\Project"; //D:\User\Proj

string color = "red blue yellow orange "; string num = "123333"; string[] strs = color.Split(" "); System.Console.WriteLine(string.Join("-",strs)); // red-blue-yellow-orange- System.Console.WriteLine(color.ToUpper()); // RED BLUE YELLOW ORANGE System.Console.WriteLine(color.Replace('a','z')); // red blue yellow orznge System.Console.WriteLine(string.Concat(color, num, "xxxxz")); // red blue yellow orange 123333xxxxz

System.Console.WriteLine(color.Trim() + num); //red blue yellow orange123333 System.Console.WriteLine("blue".Trim('b')); // lue System.Console.WriteLine("blue".Substring(2)); //ue System.Console.WriteLine("blue".IndexOf('e')); //3 System.Console.WriteLine("blue".Contains("lu")); //true //داخل پرانتز های تریم میتونیم حرف بدیم که اونا رو برداره

AidaHagh commented 2 months ago

string str1 = string.Format("{0:c}\n {1:n}\n {2:00:00}", 1234, 123456, 1234567.51);
//1,234/00ريال // 123,456/00 // 12345:68

string str2 = string.Format("{0:(#).##}\n {1:0,0}\n {2:0:000}\n {3:0%}", 1234, 123456, 1234567.55, 8899999); //(1234) //123,456 //1234:568 //889999900?

AidaHagh commented 2 months ago