Skip to content

Commit

Permalink
Make all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabbasn committed Jan 9, 2024
1 parent d5ba7d0 commit 598d5bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions csharp-fundamentals-strings.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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[..5];


//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[8..(8+13)];


//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";
}
}
14 changes: 10 additions & 4 deletions csharp-fundamentals-strings.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,7 +58,11 @@ public StringBuilder two()
// 2. After adding the message, use an appropriate StringBuilder method to reverse it
// WRITE YOUR CODE BETWEEN THIS LINE...


// Found no specific reverse method for StringBuilder, so used an array instead.
sb.Append("Hello, world!");
char[] charArray = sb.ToString().ToCharArray();
Array.Reverse(charArray);
sb.Clear().Append(charArray);

// ...AND THIS LINE

Expand All @@ -72,7 +76,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
Expand All @@ -87,7 +92,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
Expand Down
4 changes: 4 additions & 0 deletions csharp-fundamentals-strings.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// See https://aka.ms/new-console-template for more information
using csharp_fundamentals_strings.Main;

Console.WriteLine("Hello, World!");
Extension ex = new Extension();
ex.two();

0 comments on commit 598d5bf

Please sign in to comment.