- 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
String class in C#
The string keyword is an alias for the System.String class. The String class has the following two properties −
Sr.No. | Property & Description |
---|---|
1 | Chars Gets the Char object at a specified position in the current Stringobject. |
2 | Length Gets the number of characters in the current String object. |
The following are some of the methods of String class −
Sr.No. | Methods & Description |
---|---|
1 | public static int Compare(string strA, string strB) Compares two specified string objects and returns an integer that indicates their relative position in the sort order. |
2 | public static int Compare(string strA, string strB, bool ignoreCase ) Compares two specified string objects and returns an integer that indicates their relative position in the sort order. However, it ignores case if the Boolean parameter is true. |
3 | public static string Concat(string str0, string str1) Concatenates two string objects. |
4 | public static string Concat(string str0, string str1, string str2) Concatenates three string objects. |
5 | public static string Concat(string str0, string str1, string str2, string str3) Concatenates four string objects. |
Let us see how to create a string and join a string in the following example −
Example
using System; namespace StringApplication { class StringProg { static void Main(string[] args) { string[] starray = new string[]{"Cricket is my life", "It is played between two teams", "It has three formats", "T20, Test Cricket and ODI", "Cricket is life" }; string str = String.Join("
", starray); Console.WriteLine(str); } } }
Advertisements