Mohanapriya R Mohanapriya R
Updated date Jun 06, 2024
In this article, we will learn how to convert uppercase characters to strings in C#. Includes a sample program and output.

Converting Uppercase to String in C#

In C#, each character is represented by a Unicode value, and uppercase characters have distinct Unicode values compared to their lowercase counterparts. Therefore, converting uppercase characters to strings involves iterating through each character in the input string and converting any uppercase characters to their corresponding string representations.

using System;

class Program
{
    static void Main(string[] args)
    {
        string input = "HI TECHIEHOOK.COM";
        string output = ConvertUppercaseToString(input);
        Console.WriteLine("Converted String: " + output);
        Console.ReadKey();
    }

    static string ConvertUppercaseToString(string input)
    {
        string result = "";
        foreach (char c in input)
        {
            if (char.IsUpper(c))
            {
                result += c.ToString();
            }
        }
        return result;
    }
}

In this program, we have a method named ConvertUppercaseToString that takes an input string and returns a string containing only the uppercase characters. Inside the method, we will iterate through each character in the input string using a foreach loop. For each character, we use the char.IsUpper method to check if it is an uppercase character. If it is, we append it to the result string.

Output:

Converted String: HITECHIEHOOKCOM

Comments (0)

There are no comments. Be the first to comment!!!