0
0
C Sharp (C#)programming~10 mins

Common string methods in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the string to uppercase.

C Sharp (C#)
string text = "hello";
string result = text.[1]();
Drag options to blanks, or click blank then click option'
AToUpper
BToLower
CTrim
DReplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToLower() which converts to lowercase instead.
Using Trim() which removes spaces but does not change case.
2fill in blank
medium

Complete the code to check if the string starts with "Hi".

C Sharp (C#)
string greeting = "Hi there!";
bool startsWithHi = greeting.[1]("Hi");
Drag options to blanks, or click blank then click option'
AStartsWith
BIndexOf
CEndsWith
DContains
Attempts:
3 left
💡 Hint
Common Mistakes
Using Contains() which checks anywhere in the string.
Using EndsWith() which checks the end of the string.
3fill in blank
hard

Fix the error in the code to find the position of 'a' in the string.

C Sharp (C#)
string word = "banana";
int position = word.[1]('a');
Drag options to blanks, or click blank then click option'
ALocate
BFind
CIndexOf
DSearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using Find() which does not exist for strings in C#.
Using Locate() or Search() which are not valid string methods.
4fill in blank
hard

Fill both blanks to create a substring from index 2 with length 4.

C Sharp (C#)
string text = "Programming";
string part = text.[1]([2], 4);
Drag options to blanks, or click blank then click option'
ASubstring
BRemove
C2
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove() which deletes characters instead of extracting.
Using wrong starting index like 4.
5fill in blank
hard

Fill all three blanks to replace 'cat' with 'dog' in the string.

C Sharp (C#)
string sentence = "The cat sat on the mat.";
string newSentence = sentence.[1]("[2]", "[3]");
Drag options to blanks, or click blank then click option'
AReplace
Bcat
Cdog
DRemove
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove() which deletes text instead of replacing.
Swapping the order of 'cat' and 'dog'.