Skip to content

Commit d018ea8

Browse files
committed
Added examples from the PHP strtr manual
1 parent 9b6744d commit d018ea8

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Program.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,34 @@ public static void Main(string[] args)
6868
Console.WriteLine("input: {0}, output: {1}", input, output);
6969
Console.WriteLine();
7070

71-
72-
7371
var animals = "dogcathorsecow";
7472
var animalsReplace = animals.Replace("dog", "cat").Replace("cat", "horse").Replace("horse", "cow").Replace("cow", "bird");
7573
var animalsStrTr = animals.StrTr(("dog", "cat"), ("cat", "horse"), ("horse", "cow"), ("cow", "bird"));
7674

7775
Console.WriteLine("animalsReplace: {0}", animalsReplace);
7876
Console.WriteLine("animalsStrTr: {0}", animalsStrTr);
77+
Console.WriteLine();
78+
79+
Console.WriteLine("\nExamples from the PHP manual:");
80+
81+
Console.WriteLine("\nExample #1 strtr() example");
82+
input = "Bäfoo Dåbar Söderström";
83+
Console.WriteLine(input+" => "+input.StrTr("äåö", "aao"));
84+
85+
Console.WriteLine("\nExample #2 example with two arguments");
86+
input = "hi all, I said hello";
87+
var trans = new (string, string)[]
88+
{
89+
("hello", "hi"),
90+
("hi", "hello")
91+
};
92+
Console.WriteLine(input+" => "+input.StrTr( trans));
93+
94+
Console.WriteLine("\nExample #3 behavior comparison");
95+
input = "baab";
96+
Console.WriteLine(input+" => "+input.StrTr("ab", "01"));
97+
Console.WriteLine(input+" => "+input.StrTr( ("ab", "01") ));
98+
Console.WriteLine();
7999

80100
}
81101
}

0 commit comments

Comments
 (0)