c# - How to convert a StringBuilder characters to uppercase

Convert StringBuilder characters to uppercase
The StringBuilder class represents a mutable String of characters. The StringBuilder class cannot be inherited. The StringBuilder class represents a String-like object whose value is a mutable sequence of characters.

Although StringBuilder and String both represent sequences of characters, they are implemented differently. The String is an immutable type. So, each operation that appears to modify a String object actually creates a new String.

The following .net c# tutorial code demonstrates how we can convert StringBuilder instance characters to uppercase. So, in this .net c# tutorial code we will convert all of the characters of a StringBuilder object to uppercase characters. Such as if a StringBuilder content is ‘Red’ then we will convert it into uppercase characters as ‘RED’.

There are no direct methods in the StringBuilder class to convert StringBuilder characters to uppercase characters. So at first, we have to convert the StringBuilder object to a String object. The StringBuilder ToString() method converts the value of a StringBuilder to a String.

Next, we will convert the String object characters to uppercase characters using the String ToUpper() method. The String ToUpper() method returns a copy of this String converted to uppercase. We hold the uppercase converted text in a String variable.

Then we will clear the StringBuilder instance. The StringBuilder Clear() method removes all characters from the current StringBuilder instance. Finally, we will append the uppercase character String instance contents to the StringBuilder instance. The StringBuilder Append() method appends the String representation of a specified object to this instance.

<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server"> 
    protected void Button1_Click(object sender, System.EventArgs e)  
        StringBuilder stringb = new StringBuilder();
        stringb.Append("Dunlin. ");
        stringb.Append("Grey Gull. ");
        stringb.Append("Victoria Crowned Pigeon.");

        Label1.Text = "stringbuilder contents: " + stringb.ToString();

        //this line convert stringbuilder characters to uppercase characters.
        string s = stringb.ToString().ToUpper();


        Label1.Text += "<br /><br />stringbuilder contents uppercase'........<br />";
        Label1.Text += stringb.ToString();
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - convert stringbuilder uppercase</title>  
    <form id="form1" runat="server">  
        <h2 style="color:MidnightBlue; font-style:italic;">  
            c# example - convert stringbuilder uppercase
        <hr width="550" align="left" color="Gainsboro" />  
        <br />  
        <br /><br /><br />
            Text="convert stringbuilder uppercase"  
More c# examples