diff --git a/csharp-fundamentals-strings.Main/Core.cs b/csharp-fundamentals-strings.Main/Core.cs index 141c9a7..a08903b 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("httpz", "https"); // 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,27 @@ 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("/")[2]; //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"; } } diff --git a/csharp-fundamentals-strings.Main/Extension.cs b/csharp-fundamentals-strings.Main/Extension.cs index ac3b7b2..2f8f97b 100644 --- a/csharp-fundamentals-strings.Main/Extension.cs +++ b/csharp-fundamentals-strings.Main/Extension.cs @@ -33,6 +33,7 @@ public void example() // 0. Print the word "Hello" // WRITE YOUR CODE BETWEEN THIS LINE... Console.WriteLine("Hello"); + // ...AND THIS LINE } @@ -43,7 +44,9 @@ public StringBuilder one() // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // WRITE YOUR CODE BETWEEN THIS LINE... + sb.Insert(0, "Hello, world!"); + //sb.Append(new char[] { 'D', 'E', 'F' }); // ...AND THIS LINE @@ -58,6 +61,17 @@ public StringBuilder two() // 2. After adding the message, use an appropriate StringBuilder method to reverse it // WRITE YOUR CODE BETWEEN THIS LINE... + // Add initially + sb.Insert(0, "Hello, world!"); + + // Get length of string + int sb_len = sb.Length; + + // Reverse string, add it to the end of initial string + sb.Append(sb.ToString().Reverse().ToArray()); + + // Remove original string using length of original string + sb.Remove(0, sb_len); // ...AND THIS LINE @@ -73,6 +87,8 @@ public StringBuilder three() // 2. After adding the message, remove the comma. // WRITE YOUR CODE BETWEEN THIS LINE... + sb.Insert(0, "Hello, world!"); + sb.Replace(",", ""); // ...AND THIS LINE @@ -88,7 +104,9 @@ public StringBuilder four() // 2. After adding the message, replace the word "world" with the word "C#" // WRITE YOUR CODE BETWEEN THIS LINE... + sb.Insert(0, "Hello, world!"); + sb.Replace("world", "C#"); // ...AND THIS LINE