C# String Programs

C# Programming Examples - Strings

A string is a collection of Unicode characters or an array of characters. In C#, string is a keyword that is an alias for the System.String class. The System.String class is immutable, which means that once created, the state cannot be changed. Strings can be used for a variety of operations such as concatenation, comparison, searching, trimming, removing, splitting, and replacing. The String class has two properties: character and length.

C# String Methods:

In C#, there are numerous string methods. Here are a few examples:

  • Concat() – It is used to concatenate two strings.
  • Compare() – It is used to compare two specified String objects.
  • Replace() – It replace specified old character with specified new character.
  • Trim() – It removes all leading and trailing whitespace from the string.
  • Remove() – It returns characters from a string.
  • Split() – It splits a string into substrings based on specified delimiter characters.
  • Substring() – It returns the substring of a given string.
  • Copy() – It creates a new String instance that has the same value as a given String.
  • IndexOf() – It returns the position of the specified character in the given string.
  • Format() – It replaces one or more format elements in a string with the string representation.
  • ToCharArray() – It converts the string to a char array.
  • ToString() – It is used to return the instance of a string.
  • ToLower() – It is used to convert the string into lowercase.

The following section contains C# programs on strings, string operations such as join, compare, split, reverse, replace, padding, and transform operations. Every example program includes the problem description, problem solution, C# code, program explanation, and run-time test cases. All C# examples have been compiled and tested on Visual Studio.

Here is the listing of C# programming examples on Strings:

advertisement
advertisement
  1. C# Programs on Strings
  2. C# Programs on Simple String Operations
  3. C# Programs on Padding, Reversal, and Trimming Operations
  4. C# Programs on Replacement and Conversion Operations
  5. C# Programs on Advanced String Operations

1. C# Programs on Strings

Program Description
String Length Program in C# C# Program to Find the Length of a String
Count Lines in a String in C# C# Program to Count the Number of Lines in a String
Count Vowels and Consonants from a String in C# C# Program to Count Number of Vowels and Consonants in a String
Frequency of “is” Word in a String in C# C# Program to Find the Frequency of “is” Word in a String
Frequency of “the” Word in a String in C# C# Program to Find the Frequency of “the” Word in a String

2. C# Programs on Simple String Operations

Program Description
String Concatenation in C# C# Program to Concatenate Two Strings
Display Date in String in C# C# Program to Display Date in String
Display Abbreviation of a Text in C# C# Program to Print the Abbreviation of a Text
All Substrings of a String in C# C# Program to Find All Substrings in a String
Sum of Numbers in String in C# C# Program to Find the Sum of Numbers in a String

3. C# Programs on Padding, Reversal, and Trimming Operations

Program Description
Reverse a String without using Reverse Function in C# C# Program to Reverse a String without using Reverse function
Reverse a String with Predefined Function in C# C# Program to Reverse a String with Predefined Function
Split a String Collections into Groups in C# C# Program to Split a String Collections into Groups
String Splitter in C# C# Program to Implement String Splitter
String Trim in C# C# Program to Trim the Given String
String Padding in C# C# Program to Perform Padding in the String

4. C# Programs on Replacement and Conversion Operations

Program Description
Replace a Character in String in C# C# Program to Replace a Character with the String
Replace a String in String in C# C# Program to Replace a String with Another String
Convert Uppercase to Lowercase in C# C# Program to Convert Upper case to Lower Case
Change Case of Character in String in C# C# Program to Convert Characters of a String to Opposite Case

5. C# Programs on Advanced String Operations

Program Description
Searching using Predefined Functions in C# C# Program to Perform Searching using Predefined Functions
Rijndael Algorithm in C# C# Program to Encrypt/Decrypt a String using Rijndael Key
Random String Generator in C# C# Program to Generate Random String
Print Strings from ArrayList in C# C# Program to Print Strings from ArrayList

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.