Skip to content

Commit bb299a3

Browse files
author
Jonatan Berg Romundgard
committed
Passed all tests.
1 parent f3ae9bf commit bb299a3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

csharp-fundamentals-strings.Main/Core.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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;
17+
public string fixedUrl => brokenUrl.Replace("httpz", "https");
1818

1919

2020
// 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
2323

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

2828

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

3333

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

3737

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

4141

4242
//TODO: 6. Set the length member below to the length of the url member
43-
public int length => 0;
43+
public int length => url.Length;
4444

4545

4646
//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;
47+
public string faqUrl => $"{protocol}://{domain}/faq";
4848
}
4949
}

csharp-fundamentals-strings.Main/Extension.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void example()
3333
// 0. Print the word "Hello"
3434
// WRITE YOUR CODE BETWEEN THIS LINE...
3535
Console.WriteLine("Hello");
36+
3637
// ...AND THIS LINE
3738
}
3839

@@ -43,7 +44,9 @@ public StringBuilder one()
4344
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
4445
// WRITE YOUR CODE BETWEEN THIS LINE...
4546

47+
sb.Insert(0, "Hello, world!");
4648

49+
//sb.Append(new char[] { 'D', 'E', 'F' });
4750

4851
// ...AND THIS LINE
4952

@@ -58,6 +61,17 @@ public StringBuilder two()
5861
// 2. After adding the message, use an appropriate StringBuilder method to reverse it
5962
// WRITE YOUR CODE BETWEEN THIS LINE...
6063

64+
// Add initially
65+
sb.Insert(0, "Hello, world!");
66+
67+
// Get length of string
68+
int sb_len = sb.Length;
69+
70+
// Reverse string, add it to the end of initial string
71+
sb.Append(sb.ToString().Reverse().ToArray());
72+
73+
// Remove original string using length of original string
74+
sb.Remove(0, sb_len);
6175

6276

6377
// ...AND THIS LINE
@@ -73,6 +87,8 @@ public StringBuilder three()
7387
// 2. After adding the message, remove the comma.
7488
// WRITE YOUR CODE BETWEEN THIS LINE...
7589

90+
sb.Insert(0, "Hello, world!");
91+
sb.Replace(",", "");
7692

7793

7894
// ...AND THIS LINE
@@ -88,7 +104,9 @@ public StringBuilder four()
88104
// 2. After adding the message, replace the word "world" with the word "C#"
89105
// WRITE YOUR CODE BETWEEN THIS LINE...
90106

107+
sb.Insert(0, "Hello, world!");
91108

109+
sb.Replace("world", "C#");
92110

93111
// ...AND THIS LINE
94112

0 commit comments

Comments
 (0)