From 2decbcbe3a1d752595838247806219383c3f23f9 Mon Sep 17 00:00:00 2001 From: dedushka <144545095+muhammadzakriashahid@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:50:22 +0200 Subject: [PATCH 1/3] Changed String to string. IDE0049 --- snippets/csharp/System/String/Replace/replace1.cs | 2 +- snippets/csharp/System/String/Replace/replace2.cs | 2 +- snippets/csharp/System/String/Replace/string.replace1.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/csharp/System/String/Replace/replace1.cs b/snippets/csharp/System/String/Replace/replace1.cs index 847d347b7d1..5e936e12f1f 100644 --- a/snippets/csharp/System/String/Replace/replace1.cs +++ b/snippets/csharp/System/String/Replace/replace1.cs @@ -5,7 +5,7 @@ public class Example public static void Main() { // - String s = "aaa"; + string s = "aaa"; Console.WriteLine("The initial string: '{0}'", s); s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d"); Console.WriteLine("The final string: '{0}'", s); diff --git a/snippets/csharp/System/String/Replace/replace2.cs b/snippets/csharp/System/String/Replace/replace2.cs index e7f77c54ca9..f3ca83500c2 100644 --- a/snippets/csharp/System/String/Replace/replace2.cs +++ b/snippets/csharp/System/String/Replace/replace2.cs @@ -5,7 +5,7 @@ public class Example public static void Main() { // - String s = new String('a', 3); + string s = new String('a', 3); Console.WriteLine("The initial string: '{0}'", s); s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd'); Console.WriteLine("The final string: '{0}'", s); diff --git a/snippets/csharp/System/String/Replace/string.replace1.cs b/snippets/csharp/System/String/Replace/string.replace1.cs index 5164f6da247..c70171c917e 100644 --- a/snippets/csharp/System/String/Replace/string.replace1.cs +++ b/snippets/csharp/System/String/Replace/string.replace1.cs @@ -3,7 +3,7 @@ class stringReplace1 { public static void Main() { // - String str = "1 2 3 4 5 6 7 8 9"; + string str = "1 2 3 4 5 6 7 8 9"; Console.WriteLine("Original string: \"{0}\"", str); Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ',')); From fbe367c4f365736f3674209a047376b2c31ffd78 Mon Sep 17 00:00:00 2001 From: muhammadzakriashahid Date: Wed, 11 Sep 2024 11:37:05 +0200 Subject: [PATCH 2/3] Added csproj for string replace. --- snippets/csharp/System/String/Replace/Project.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 snippets/csharp/System/String/Replace/Project.csproj diff --git a/snippets/csharp/System/String/Replace/Project.csproj b/snippets/csharp/System/String/Replace/Project.csproj new file mode 100644 index 00000000000..24f58ecd991 --- /dev/null +++ b/snippets/csharp/System/String/Replace/Project.csproj @@ -0,0 +1,8 @@ + + + + Exe + net8.0 + + + \ No newline at end of file From f9f16d7a7364552ecbaa2e06cf88dd3e47266d81 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 13 Sep 2024 09:10:32 -0700 Subject: [PATCH 3/3] fix compilation errors --- snippets/csharp/System/String/Replace/Program.cs | 4 ++++ snippets/csharp/System/String/Replace/replace1.cs | 6 +++--- snippets/csharp/System/String/Replace/replace2.cs | 8 ++++---- .../csharp/System/String/Replace/string.replace1.cs | 10 ++++++---- snippets/csharp/System/String/Replace/stringreplace.cs | 9 +++------ 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 snippets/csharp/System/String/Replace/Program.cs diff --git a/snippets/csharp/System/String/Replace/Program.cs b/snippets/csharp/System/String/Replace/Program.cs new file mode 100644 index 00000000000..83c629bb8a5 --- /dev/null +++ b/snippets/csharp/System/String/Replace/Program.cs @@ -0,0 +1,4 @@ +//Example1.Main(); +//Example2.Main(); +//Example3.Main(); +Example4.Main(); diff --git a/snippets/csharp/System/String/Replace/replace1.cs b/snippets/csharp/System/String/Replace/replace1.cs index 5e936e12f1f..e51d5798fb7 100644 --- a/snippets/csharp/System/String/Replace/replace1.cs +++ b/snippets/csharp/System/String/Replace/replace1.cs @@ -1,14 +1,14 @@ using System; -public class Example +public class Example1 { public static void Main() { // string s = "aaa"; - Console.WriteLine("The initial string: '{0}'", s); + Console.WriteLine($"The initial string: '{s}'"); s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d"); - Console.WriteLine("The final string: '{0}'", s); + Console.WriteLine($"The final string: '{s}'"); // The example displays the following output: // The initial string: 'aaa' diff --git a/snippets/csharp/System/String/Replace/replace2.cs b/snippets/csharp/System/String/Replace/replace2.cs index f3ca83500c2..fa88b768e18 100644 --- a/snippets/csharp/System/String/Replace/replace2.cs +++ b/snippets/csharp/System/String/Replace/replace2.cs @@ -1,14 +1,14 @@ using System; -public class Example +public class Example2 { public static void Main() { // - string s = new String('a', 3); - Console.WriteLine("The initial string: '{0}'", s); + string s = new('a', 3); + Console.WriteLine($"The initial string: '{s}'"); s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd'); - Console.WriteLine("The final string: '{0}'", s); + Console.WriteLine($"The final string: '{s}'"); // The example displays the following output: // The initial string: 'aaa' diff --git a/snippets/csharp/System/String/Replace/string.replace1.cs b/snippets/csharp/System/String/Replace/string.replace1.cs index c70171c917e..ae9f96e60d3 100644 --- a/snippets/csharp/System/String/Replace/string.replace1.cs +++ b/snippets/csharp/System/String/Replace/string.replace1.cs @@ -1,11 +1,13 @@ using System; -class stringReplace1 { - public static void Main() { +class Example3 +{ + public static void Main() + { // string str = "1 2 3 4 5 6 7 8 9"; - Console.WriteLine("Original string: \"{0}\"", str); - Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ',')); + Console.WriteLine($"Original string: \"{str}\""); + Console.WriteLine($"CSV string: \"{str.Replace(' ', ',')}\""); // This example produces the following output: // Original string: "1 2 3 4 5 6 7 8 9" diff --git a/snippets/csharp/System/String/Replace/stringreplace.cs b/snippets/csharp/System/String/Replace/stringreplace.cs index 8b74b18173a..118ac67fe7b 100644 --- a/snippets/csharp/System/String/Replace/stringreplace.cs +++ b/snippets/csharp/System/String/Replace/stringreplace.cs @@ -1,21 +1,18 @@ using System; -public class ReplaceTest +public class Example4 { public static void Main() { - // string errString = "This docment uses 3 other docments to docment the docmentation"; - Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString); + Console.WriteLine($"The original string is:{Environment.NewLine}'{errString}'{Environment.NewLine}"); // Correct the spelling of "document". - string correctString = errString.Replace("docment", "document"); - Console.WriteLine("After correcting the string, the result is:{0}'{1}'", - Environment.NewLine, correctString); + Console.WriteLine($"After correcting the string, the result is:{Environment.NewLine}'{correctString}'"); // This code example produces the following output: //