Create string from char array
The following asp.net c# example code demonstrate us how can we create a string object from a char array
programmatically at run time in an asp.net application. Char array represent an array whose each element value
represent a single Unicode character.
.Net framework's String Class has several constructors to initialize a new String Class (string object). String Class String(Char[]) constructor allow us to initialize a new instance of the String Class to the value indicated by an array of Unicode characters (char array). We just need to pass a char array object as a parameter of this constructor.
Finally, we can create a string object from a char array by this way String Newstring = new String(CharArray). The newly created string contains the value populated from specified char array values (Unicode characters).
.Net framework's String Class has several constructors to initialize a new String Class (string object). String Class String(Char[]) constructor allow us to initialize a new instance of the String Class to the value indicated by an array of Unicode characters (char array). We just need to pass a char array object as a parameter of this constructor.
Finally, we can create a string object from a char array by this way String Newstring = new String(CharArray). The newly created string contains the value populated from specified char array values (Unicode characters).
create-string-from-char-array.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
char[] chararray = { 'b','a','n','g','l','a','d','e','s','h'};
Label1.Text = "char array.....<br />";
foreach (char c in chararray)
{
Label1.Text += c + " | ";
}
string txt = new string(chararray);
Label1.Text += "<br /><br />char array to string: " + txt;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - create string from char array</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
c# example - create string from char array
</h2>
<hr width="550" align="left" color="LightBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="create string from char array"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to merge two arrays without duplicates
- How to merge two arrays
- How to create a char array
- How to get dimension length of an array
- How to get difference between two arrays
- How to initialize an empty array
- How to make array except
- How to find an element from an array
- How to find all elements from an array that match the conditions
- How to perform foreach loop through an array elements