String repeat character
The following asp.net c# example code demonstrate us how can we create a string by repeating a character
programmatically at run time in an asp.net application. .Net framework's String Class represent text as a series of
Unicode characters. We can initialize a new string object using several constructors.
String constructor String(Char, Int32) initialize a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times. String(Char, Int32) constructor has two required parameters named 'c' and 'count'.
The 'c' parameter value data type is System.Char which represent a Unicode character to repeat. The 'count' property value represent the number of times specified character repeat. After passing both parameters value to this constructor, we get a string where a specified character repeated specified number of times.
String(Char, Int32) constructor throw ArgumentOutOfRangeException, if the 'count' parameter value is less than zero (0).
String constructor String(Char, Int32) initialize a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times. String(Char, Int32) constructor has two required parameters named 'c' and 'count'.
The 'c' parameter value data type is System.Char which represent a Unicode character to repeat. The 'count' property value represent the number of times specified character repeat. After passing both parameters value to this constructor, we get a string where a specified character repeated specified number of times.
String(Char, Int32) constructor throw ArgumentOutOfRangeException, if the 'count' parameter value is less than zero (0).
string-repeat-character.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this line create a string by repeated characters.
string repeatedCharacters = new string('M',10);
Label1.Text += "<br />string of repeated characters........<br />";
Label1.Text += repeatedCharacters;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string repeat character</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string repeat character
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string repeat character"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to get number of characters from right side of a string
- How to get number of characters from left side of a string
- How to trim the last character of a string
- How to remove white spaces from strating of a string
- How to truncate a string
- How to trim a string to a specified length
- How to convert a string to a datetime object
- How to convert a string to double
- How to convert a string to float
- How to parse a string into char