- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34494 Articles for Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
65 Views
Set the string.StringBuilder str = new StringBuilder("Tom Hanks");Now, use the replace() method to replace whitespace with String. Empty. This will eventually remove the whitespace.str.Replace(" ", String.Empty);Let us see the complete code −Example Live Demousing System; using System.Text; class Demo { static void Main() { StringBuilder str = new StringBuilder("Tom Hanks"); Console.WriteLine(str.ToString()); str.Replace(" ", String.Empty); Console.WriteLine(str.ToString()); Console.ReadLine(); } }OutputTom Hanks TomHanks
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
269 Views
The following is our string −string myStr = "5";To check whether the above is a string with numeric representation, use TryParse and out.int.TryParse(myStr, out a);Here is the complete code.Example Live Demousing System.IO; using System; class Program { static void Main() { bool res; int a; string myStr = "5"; // checking for valid string representation of a number res = int.TryParse(myStr, out a); Console.WriteLine(res); } }OutputTrue
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
To validate, you need to check for the protocols.http httpsWith that, you need to check for .com, .in, .org, etc.For this, use the following regular expression −(http|http(s)?://)?([\w-]+\.)+[\w-]+[.com|.in|.org]+(\[\?%&=]*)?The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; namespace RegExApplication { class Program { private static void showMatch(string text, string expr) { Console.WriteLine("The Expression: " + expr); MatchCollection mc = Regex.Matches(text, expr); foreach (Match m in mc) { Console.WriteLine(m); } } ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
9K+ Views
Use Hashset to remove duplicate characters.Here is the string −string myStr = "kkllmmnnoo";Now, use HashSet to map the string to char. This will remove the duplicate characters from a string.var unique = new HashSet(myStr);Let us see the complete example −Example Live Demousing System; using System.Linq; using System.Collections.Generic; namespace Demo { class Program { static void Main(string[] args) { string myStr = "kkllmmnnoo"; Console.WriteLine("Initial String: "+myStr); var unique = new HashSet(myStr); Console.Write("New String after removing duplicates: "); foreach (char c in unique) Console.Write(c); } } }OutputInitial String: kkllmmnnoo New String after removing duplicates: klmno
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
4K+ Views
Convert a string representation of number to an integer, using the int.TryParse and intParse method in C#.If the string cannot be converted, then the int.TryParse method returns false i.e. a Boolean value, whereas int.Parse returns an exception.Let us see an example of int.Parse method −Example Live Demousing System.IO; using System; class Program { static void Main() { int res; string myStr = "120"; res = int.Parse(myStr); Console.WriteLine("String is a numeric representation: "+res); } }OutputString is a numeric representation: 120Let us see an example of int.TryParse method.Example Live Demousing ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
Set two arrays.var val = new [] { 20, 40, 60}; var str = new [] { "ele1", "ele2", "ele3"};Use the zip() method to process the two arrays in parallel.var res = val.Zip(str, (n, w) => new { Number = n, Word = w });The above fetches both the arrays with int and string elements respectively.Now, use foreach to iterate the two arrays −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { var val = new [] { 20, 40, 60}; var str = new ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
214 Views
Firstly, set two lists in C#.List OneList list1 = new List (); list1.Add("P"); list1.Add("Q"); list1.Add("R"); list1.Add("S"); list1.Add("T"); list1.Add("U"); list1.Add("V"); list1.Add("W");List TwoList list2 = new List (); list2.Add("T"); list2.Add("U"); list2.Add("V"); list2.Add("W");Now, to get the different values in both the lists, use the Except method. It returns the values in the first list which is not present in the second list.Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List list1 = new List (); list1.Add("P"); list1.Add("Q"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
678 Views
The Func generic type store anonymous methods and is a parameterized type.In the below example, we have 4 func type instance −The first type receives int and returns stringFunc one = (p) => string.Format("{0}", p);The second type receives bool & long and returns stringFunc two = (q, p) =>string.Format("{0} and {1}", q, p);The third type receives bool & int and returns stringFunc three = (q, p) => string.Format("{0} and {1}", q, p);The fourth type receives decimal and returns stringFunc four = (p) =>string.Format("{0}", p);Let us see how to display them −Example Live Demousing System; using System.IO; namespace Demo { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
240 Views
EnumerateFile() method is used in C# to get all the files. Use AllDirectories property to recurse through directories −Directory.EnumerateFiles(@"D:\NEW", "*.*", SearchOption.AllDirectories)To get the list of files in a directory, use the SearchOptions.AllDirectories in C# as shown above.Let us see how −Exampleusing System; using System.IO; namespace Demo { class Program { static void Main(string[] args) { foreach (string allFiles is Directory.EnumerateFiles(@"D:\NEW","*.*",SearchOption.AllDirectories)) { Console.WriteLine(allFiles); } } } }OutputThe following is the output −D:\NEW\my.txt D:\NEW\amit.html D:\NEW\tutorials\java\a.java