String find all occurrences
string-find-all-occurrences.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
//this section create a string variable.
string plants = "Black Cherry. Cabinet Cherry. Skunk Cabbage. Wild Cherry";
Label1.Text = "string of plants..................<br />";
Label1.Text += plants+"<br />";
//substring to find/search indexes/occurrences in string.
string indexOfSubStringToFind = "Cherry";
int index = 0;
Label1.Text += "<br /><br />substring [Cherry] found in following index position in string";
//find all indexes/occurrences of specified substring in string
while ((index=plants.IndexOf(indexOfSubStringToFind, index)) != -1)
{
Label1.Text += "<br />" + index;
index++;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string find all occurrences</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string find all occurrences
</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 find all occurrences"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to format a string as currency without decimal
- How to format a string as currency with dollar sign
- How to format a string as negative currency
- How to format a string as a date
- How to determine whether a string is equals to another string
- String equals case insensitive
- How to escape double quotes in a string
- How to find a substring within a string
- How to find index of a substring in a string
- How to find first index of a character within a string