Skip to content

Commit 44fd693

Browse files
author
Jone Hjorteland
committed
Finished exercise and extentions
1 parent f3ae9bf commit 44fd693

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

csharp-fundamentals-strings.Main/Core.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,29 @@ public class Core
1414
//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).
1515
// Using the `replace` method on brokenUrl, set the fixedUrl member below to the correct value.
1616
// https://learn.microsoft.com/en-us/dotnet/api/system.string.replace?view=net-7.0
17-
public string fixedUrl => string.Empty;
18-
17+
public string fixedUrl => brokenUrl.Replace('z', 's');
1918

2019
// Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements:
2120
// https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-7.0
2221

23-
2422
//TODO: 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above,
2523
// set the value of lowerCasedUrl.
26-
public string lowerCasedUrl => string.Empty;
27-
24+
public string lowerCasedUrl => fixedUrl.ToLower();
2825

2926
//TODO: 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space
3027
// and set the value of the url member below
31-
public string url => string.Empty;
32-
28+
public string url => lowerCasedUrl.Trim();
3329

3430
//TODO: 4. Using the appropriate string method on url, set the value of the protocol member below
35-
public string protocol => string.Empty;
36-
31+
public string protocol => url.Split(':')[0];
3732

3833
//TODO: 5. Using the appropriate string method on url, set the value of the domain member below
39-
public string domain => string.Empty;
40-
34+
public string domain => url.Split('/')[2];
4135

4236
//TODO: 6. Set the length member below to the length of the url member
43-
public int length => 0;
44-
37+
public int length => url.Length;
4538

4639
//TODO: 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website
47-
public string faqUrl => string.Empty;
40+
public string faqUrl => url.Replace("who-we-are", "faq");
4841
}
4942
}

csharp-fundamentals-strings.Main/Extension.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public StringBuilder one()
4343
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
4444
// WRITE YOUR CODE BETWEEN THIS LINE...
4545

46-
46+
sb.Append("Hello, world!");
4747

4848
// ...AND THIS LINE
4949

@@ -58,7 +58,10 @@ public StringBuilder two()
5858
// 2. After adding the message, use an appropriate StringBuilder method to reverse it
5959
// WRITE YOUR CODE BETWEEN THIS LINE...
6060

61+
// StringBuilder does not have built-in method for reversing.
6162

63+
sb.Append("Hello, world!");
64+
sb = new StringBuilder(new string(sb.ToString().Reverse().ToArray()));
6265

6366
// ...AND THIS LINE
6467

@@ -73,7 +76,8 @@ public StringBuilder three()
7376
// 2. After adding the message, remove the comma.
7477
// WRITE YOUR CODE BETWEEN THIS LINE...
7578

76-
79+
sb.Append("Hello, world!");
80+
sb.Remove(5, 1);
7781

7882
// ...AND THIS LINE
7983

@@ -88,7 +92,8 @@ public StringBuilder four()
8892
// 2. After adding the message, replace the word "world" with the word "C#"
8993
// WRITE YOUR CODE BETWEEN THIS LINE...
9094

91-
95+
sb.Append("Hello, world!");
96+
sb.Replace("world", "C#");
9297

9398
// ...AND THIS LINE
9499

0 commit comments

Comments
 (0)