String to int list
string-to-int-list.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 variable.
string stringOfNumbers = "1,5,125,500,99,,250";
Label1.Text = "string of numbers............<br />";
Label1.Text += stringOfNumbers;
//split string and create a generic list with int data type.
//it also remove empty elements.
List<int> listOfInteger = stringOfNumbers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
Label1.Text += "<br /><br />list of numbers............";
foreach (int number in listOfInteger)
{
Label1.Text += "<br />" + number;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string to int list</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string to int list
</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 to int list"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to format a string as negative currency
- How to perform regex case insensitive string replace
- How to append a substring to a string
- How to check whether a string starts with number
- How to remove a character from a string at specified position
- How to format a string as datetime yyyyMMdd
- How to get bytes from a string
- How to convert a string to an IP address
- How to convert a string to an int array
- How to split a string to key value pairs