Solved

# 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?

Posted on 2005-03-31
Medium Priority
208 Views
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?
0
Question by:musclejack
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 4

Expert Comment

ID: 13675302
here ya go.

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.
0

LVL 75

Accepted Solution

Anthony Perkins earned 800 total points
ID: 13677814
Const BR As String = "<br>"

Dim MyString As String = "Hello<br>My<br>Friend<br>"
Dim NumberOfBRs As Integer = (MyString.Length - MyString.Replace(BR, "").Length) / BR.Length
0

LVL 75

Expert Comment

ID: 13677825
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
0

LVL 39

Assisted Solution

appari earned 200 total points
ID: 13678271
Just a correction;
acperkins :
i think Dim NumberOfBRs As Integer = (MyString.Length - MyString.Replace(BR, String.Empty).Length)  is enough, no need to divide with length of BR

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

in the example MyString length is 25
after replacing <Br> with empty string length will be 22
25-22 gives 3
if we divide it with 4 (length of <br>)?
0

LVL 39

Expert Comment

ID: 13678449
ignore my comment acperkins is correct.
acperkins :
i am sorry i calculated it wrong:(

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
###### Suggested Courses
Course of the Month9 days, 1 hour left to enroll