Quindi ho una lista con oggetti Materiel. In Materiel ho 15 metodi get e set. Voglio costruire un metodo di ricerca che cerchi tutti gli oggetti nella lista e tutte le variabili in ogni oggetto Materiel. La parte di loop è abbastanza facile, ma sto lottando con la stringa-contiene-parte. Il termine di ricerca potrebbe ad esempio essere "acto", e dovrei ottenere un successo per "Tractor". Ho provato a utilizzare la classe string-Contains, ma per quanto posso capire controlla solo la stringa che inizia nella posizione 0. Quindi "Tra" ottiene un hit, ma non "acto".C# contiene parte della stringa
C'è qualche build in classi, o dovrei programmarne uno da solo?
Ci scusiamo per la cattiva spiegazione.
Il mio codice. Vedo ora che ottengo risultati per la stringa, ma anche altri risultati :)
protected void Button_search_Click(object sender, EventArgs e)
{
string searchTerm = TextBox1.Text.ToString().ToLower();
TableRow row;
TableCell cell;
int rowNumber = 1;
foreach (Materiell mat in allItems)
{
if (searchTerm.Contains(mat.itemID.ToString().ToLower()) ||
searchTerm.Contains(mat.manufacturer.ToLower()) ||
searchTerm.Contains(mat.model.ToLower()) ||
searchTerm.Contains(mat.serialNo.ToLower()) ||
searchTerm.Contains(mat.dateProd.ToString().ToLower()) ||
searchTerm.Contains(mat.location.ToLower()) ||
searchTerm.Contains(mat.mainCategory.ToLower()) ||
searchTerm.Contains(mat.subCategory.ToLower()) ||
searchTerm.Contains(mat.dateAcquired.ToString().ToLower()) ||
searchTerm.Contains(mat.price.ToString().ToLower()) ||
searchTerm.Contains(mat.ownerID.ToString().ToLower()) ||
searchTerm.Contains(mat.extra.ToString().ToLower()) ||
searchTerm.Contains(mat.textComment.ToLower()) ||
searchTerm.Contains(mat.active.ToString().ToLower()))
{
row = new TableRow();
row.ID = "row" + rowNumber.ToString();
rowNumber++;
cell = new TableCell();
cell.Text = "<a href=\"#\" class=\"opendiv\">" + mat.itemID.ToString() + "</a>";
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.manufacturer.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.model.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.serialNo.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.dateProd.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.location.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.mainCategory.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.subCategory.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.dateAcquired.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.price.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.ownerID.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.extra.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.ownDefData.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.textComment.ToString();
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = mat.active.ToString();
row.Cells.Add(cell);
Table1.Rows.Add(row);
}
}
}
Potrebbe inviare un frammento di codice perché secondo la documentazione "acto" dovrebbe colpire in "Trattore": http://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.100).aspx – LexyStardust
'" Trattore ".Contains (" acto ")' dovrebbe restituire 'true'. Potresti postare parte del tuo codice in modo da poter vedere ciò che hai provato finora e dove potresti sbagliare. – Rawling
Gah. Nessuna delle risposte risponde al punto. Guarda Lucene.NET, forse (sembra che tu stia cercando la ricerca/indicizzazione di testo completo, è forse un'applicazione di tipo libreria?) – sehe