I am building a web application where it has text sets.
eg.
Mayan Civilization - TextSet1
The Maya civilization shares many features with other Mesoamerican civilizations due to the high degree of interaction and cultural diffusion that characterized the region. Advances such as writing, epigraphy, and the calendar did not originate with the Maya;
Maya Influence - TextSet2
however, their civilization fully developed them. Maya influence can be detected from Honduras, Belize, Guatemala, and western El Salvador to as far away as central Mexico, more than 1,000 km (620 mi) from the Maya area. Many outside influences are found in Maya art and architecture, which are thought to result from trade and cultural exchange rather than direct external conquest.
Question
Each TextSet has a unique index since they are stored in a Gridview
. The code I have loops through each item or index in the GridView
by first storing the first item which is TextSet1
in a string.
Then, another For loop
which loops through that string in order to count
how many matches are there of the word Maya
.
For Each item As GridViewRow In Me.GridViewSearchResult.Rows
Dim txtStr as Label = DirectCast(item.FindControl("TextSet1"), Label)
Dim Str = txtStr.Text.toString
For i as Integer = 0 to Str.Length - 1
Dim count As new Integer
count = Regex.Matches (Str, "Maya", RegexOptions.IgnoreCase).Count
Next
Next
What I am trying to achieve is that in the start, the program starts by handling TextSet1
or Str
and then counts using count
how many occurrences of the word Maya
in Str
. On the first occurrence of Maya
in Str
, store the entire set in the database and then exit or stop the loop. This means that the program will not move to TextSet2
. I thought of performing a check outside the loop and then calling the values, however Str
is declared within the For loop
. Also tried to do a Regex.match
outside the loop, but what I need is to stop the loop on the first occurance of the word maya
in the Str
currently in that loop. Any suggestions or thoughts of how can achieve that ?