From 0feca80b595de4f2932ad8b84fd13ed2f3511404 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 12 Aug 2024 14:32:14 +0200 Subject: [PATCH 1/4] Core tests complete --- csharp-fundamentals-strings.Main/Core.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/csharp-fundamentals-strings.Main/Core.cs b/csharp-fundamentals-strings.Main/Core.cs index 141c9a7..a20c7d1 100644 --- a/csharp-fundamentals-strings.Main/Core.cs +++ b/csharp-fundamentals-strings.Main/Core.cs @@ -14,7 +14,7 @@ public class Core //TODO: 1. The brokenUrl member above contains an invalid URL. There's a z instead of an s in the protocol (httpz instead of https). // Using the `replace` method on brokenUrl, set the fixedUrl member below to the correct value. // https://learn.microsoft.com/en-us/dotnet/api/system.string.replace?view=net-7.0 - public string fixedUrl => string.Empty; + public string fixedUrl => brokenUrl.Replace("z", "s"); // Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements: @@ -23,27 +23,26 @@ public class Core //TODO: 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above, // set the value of lowerCasedUrl. - public string lowerCasedUrl => string.Empty; + public string lowerCasedUrl => fixedUrl.ToLower(); //TODO: 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space // and set the value of the url member below - public string url => string.Empty; - + public string url => lowerCasedUrl.Trim(); //TODO: 4. Using the appropriate string method on url, set the value of the protocol member below - public string protocol => string.Empty; + public string protocol => url.Split(':')[0]; //TODO: 5. Using the appropriate string method on url, set the value of the domain member below - public string domain => string.Empty; + public string domain => url.Split("//")[1].Split('/')[0]; //TODO: 6. Set the length member below to the length of the url member - public int length => 0; + public int length => url.Length; //TODO: 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website - public string faqUrl => string.Empty; + public string faqUrl => protocol + "://" + domain + "/faq"; } } From a5399e7890b6c1e1e1e987e06869fa59dbc35564 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 12 Aug 2024 15:05:21 +0200 Subject: [PATCH 2/4] almost all extensions done --- csharp-fundamentals-strings.Main/Extension.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/csharp-fundamentals-strings.Main/Extension.cs b/csharp-fundamentals-strings.Main/Extension.cs index ac3b7b2..c328d33 100644 --- a/csharp-fundamentals-strings.Main/Extension.cs +++ b/csharp-fundamentals-strings.Main/Extension.cs @@ -42,7 +42,7 @@ public StringBuilder one() // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // WRITE YOUR CODE BETWEEN THIS LINE... - + sb.Append("Hello, world!"); // ...AND THIS LINE @@ -57,9 +57,8 @@ public StringBuilder two() // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, use an appropriate StringBuilder method to reverse it // WRITE YOUR CODE BETWEEN THIS LINE... - - - + sb.Append("Hello, world!"); + // ...AND THIS LINE return sb; @@ -72,8 +71,8 @@ public StringBuilder three() // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, remove the comma. // WRITE YOUR CODE BETWEEN THIS LINE... - - + sb.Append("Hello, world!"); + sb.Replace(",", ""); // ...AND THIS LINE @@ -87,7 +86,8 @@ public StringBuilder four() // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, replace the word "world" with the word "C#" // WRITE YOUR CODE BETWEEN THIS LINE... - + sb.Append("Hello, world!"); + sb.Replace("world", "C#"); // ...AND THIS LINE From 1387bda19624ca24c8c08004547a6be6e45221dc Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 12 Aug 2024 15:51:05 +0200 Subject: [PATCH 3/4] Extension also complete, --- csharp-fundamentals-strings.Main/Extension.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/csharp-fundamentals-strings.Main/Extension.cs b/csharp-fundamentals-strings.Main/Extension.cs index c328d33..c038140 100644 --- a/csharp-fundamentals-strings.Main/Extension.cs +++ b/csharp-fundamentals-strings.Main/Extension.cs @@ -58,7 +58,13 @@ public StringBuilder two() // 2. After adding the message, use an appropriate StringBuilder method to reverse it // WRITE YOUR CODE BETWEEN THIS LINE... sb.Append("Hello, world!"); - + string reverseString = ""; + for(int i = sb.Length - 1; i >= 0 ; i--) + { + reverseString += sb[i]; + } + sb.Clear(); + sb.Append(reverseString); // ...AND THIS LINE return sb; From c1b072a815e832f5e1d4800c5d014df131c24df0 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 12 Aug 2024 16:15:28 +0200 Subject: [PATCH 4/4] all done, last extension answered --- csharp-fundamentals-strings.Main/Extension.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/csharp-fundamentals-strings.Main/Extension.cs b/csharp-fundamentals-strings.Main/Extension.cs index c038140..7f9ed08 100644 --- a/csharp-fundamentals-strings.Main/Extension.cs +++ b/csharp-fundamentals-strings.Main/Extension.cs @@ -67,6 +67,9 @@ public StringBuilder two() sb.Append(reverseString); // ...AND THIS LINE + //technically this isn't a Stringbuilder method. That's because there isn't one in the documentation for Stringbuilder + // this could also be solved by making it into a char array and use Reverse() on that array + return sb; }