Created
November 23, 2021 12:10
-
-
Save rozer007/e5d2c9d3cc0a8a3ccc8130f0a44d7749 to your computer and use it in GitHub Desktop.
STRING , STRINGBUILDER AND ITS FUNCTION IN C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) What is the difference between String and stringbuilder? | |
ans: string are immutable whereas Stringbuilder are mutable. | |
Q2) What is the function to trim only the leftside of the string? | |
ans: TrimStart function is use to trim the left side of the string and TrimEnd function is use to trim the right side of the string. | |
Q3)How to find whether a string is present in a string ? | |
ans: To check whether whether a string is present in the string or not , we will use the Contains function. | |
string st="hello pepcoder"; | |
Console.WriteLine(st.Contains("hello")); => true | |
Q4) What is the difference between append and appendformar in stringbuilder? | |
ans: Append function is used to append just a simple string eg. str.append("hello"). | |
AppendFormat function is used to append formatted string in a stringbuilder eg.str.append("hello {0}","pepcoder"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1) What will be the output of this code? | |
string str="hello pepcoder"; | |
Console.WriteLine(str.Substring(0,8)); | |
a) hello pe | |
b) hello pep | |
c) ello pe | |
d) ello pep | |
ans: b) | |
Q2) Output of this code? | |
string str="hello pepcoder"; | |
Console.WriteLine(str.StartsWith("He")); | |
a) error | |
b) true | |
c) false | |
d) 0 | |
ans: c) | |
Q3) What will be the output? | |
string str="hello pepcoder"; | |
Console.WriteLine(str.Equals("Hello pepcoder",StringComparison.OrdinalIgnoreCase)); | |
a) true | |
b) false | |
c) none | |
d) any of the above | |
ans: a)true | |
Q4) What is the output of this code? | |
StringBuilder str= new StringBuilder ("hello pepcoder"); | |
str.Remove(2,3); | |
Console.WriteLine(str.ToString()); | |
a) hel pepcoder | |
b) he pepcoder | |
c) hell pepcoder | |
d) None of the above | |
ans: b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment