I am looking how to iterate trough a string with word, starting at the end and going to the start, word by word.
The output should be like:
- word1 word2 word3 word4
- word1 word2 word3
- word1 word2
- word1
I don't really now where/how to start. The other way around I got working, but it turned out that's not what I need (see below).
string descriptionText = "Column Grid Building"; //example
string[] description1TextArray = descriptionText.Split(' ');
int noItems = description1TextArray.Count();
for (int i = 0; i < noItems; i++)
{
if (i == 0)
{
search = search + description1TextArray[i];
}
else
{
search = search + " " + description1TextArray[i];
}
foreach (DataRow row in dt.Rows)
{
description1 = row[0].ToString();
abbreviation1 = row[1].ToString();
if (description1 == search || abbreviation1 == search)
{
comboBoxDescription1.SelectedIndex = comboBoxDescription1.FindStringExact(description1);
}
}
}
EDIT:
Sorry for any confusion.
I start with a string "word1 word2 word3 word4". I already have each word set to an array.
string[] description1TextArray = descriptionText.Split(' ');
int noItems = description1TextArray.Count();
I need to check a string against a value from a datatable. For example the value in dataTable is "Column Grid". My input is "Column Grid Building".
The reason I need to check from end to start is because there are values in the data table that overlap, like "Column Grid" and "Columnn". When I do the check on the string from start to end, the value "Column Grid" is never found because a match is already found on "Column".
I hope this explains it better.