Search⌘ K
AI Features

Built-in String and Array Functions

Explore built-in string and array methods in C# that help manipulate text and data efficiently. Learn how to use case-changing, searching, and replacement functions for strings. Understand array operations like inserting, copying, clearing, reversing, and sorting to manage collections effectively in your programs.

Built-in functions for strings

C# provides various built-in functions for dealing with strings. These functions are collectively called string methods.

Note: All string methods return a new string without changing the original one.

There are numerous tasks related to strings that make it easy for programmers to perform routine tasks. This section will provide examples and results of some commonly used string methods.

The methods related to case change

These methods change the letter case of the text stored in a string (say, from lowercase to uppercase). Let’s use an example program to explore case changes.

  • The ToLower() method converts all characters in a string to lowercase.
  • The ToUpper() method converts all characters in a string to uppercase.
C#
class Test
{
static void Main()
{
System.Console.WriteLine("EDUCATIVE".ToLower());
System.Console.WriteLine("educative".ToUpper());
}
}

The search-related functions

These functions search for the occurrence of text in a string. Let’s use an example program to explore searches.

  • The Compare() compares two strings and return 00 if both strings are equal.

  • The EndsWith() checks whether the ...