2
Answers

Search through string in a string

Rob Angelier

Rob Angelier

14y
2.4k
1

Hello guys,
i'm new here and new to C# programming, but trying hard to learn it.
Question
I need to store two values (string, int) in one object. Wich object can i use best?
Situation
I'm writing a small program that is going to search through a couple of text blocks and returns how many times the word that the user has filled in by input appears in the corresponding text. After this i need to sort these items with the most returns at the top, DESC i think?
Looking forward to your replies!
beste regards,
 
Rob
Answers (2)
0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 14y
I am a little confused. You say you need to show "how many times the word" appears, which is just one number. You also say "i need to sort these items", so I am not sure what you need to sort. Are you saying that you need to show the number of occurances for all words in the text? If so then I assume you need to write the code so that there can be multiple words that have the same number of occurances, which makes things a bit more complicated.
0
Jaish Mathews

Jaish Mathews

NA 7.3k 1.2m 14y

try this
SortedList<int, string> sl = new SortedList<int, string>();
sl.Add(2,
"st1");
sl.Add(5,
"st2");
sl.Add(1,
"str3");