musclejack
asked on
hi i have a string = "Hello<br>My<br>Friend<br>". how can i get the number of "<br>" from this string in asp.net?
hi i have a string = "Hello<br>My<br>Friend<br> ". how can i get the number of "<br>" from this string in asp.net?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Let's try that again:
Const BR As String = "<br>"
Dim MyString As String = "Hello<br>My<br>Friend<br> "
Dim NumberOfBRs As Integer = (MyString.Length - MyString.Replace(BR, String.Empty).Length) / BR.Length
Const BR As String = "<br>"
Dim MyString As String = "Hello<br>My<br>Friend<br>
Dim NumberOfBRs As Integer = (MyString.Length - MyString.Replace(BR, String.Empty).Length) / BR.Length
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ignore my comment acperkins is correct.
acperkins :
i am sorry i calculated it wrong:(
acperkins :
i am sorry i calculated it wrong:(
string brString = "Hello<br>My<br>Friend<br>
// Count holds the number of <br>s found
int count = 0;
// Loops until it can't find any instance of <br> in the string
while(true)
{
// finds the location of the first <br> in the string
int i = brString.IndexOf("<br>");
if(i < 0)
{
break;
}
// Gets rid of the string up to and including the <br>
brString = brString.Substring(i+4);
count++;
}
So now count represents the number of <br>s found. If you don't want to lose the string, just put the value into a temporary string.