I have a string array i.e.
string[] input_Text = new string[] { "i am wanting to take admission in the univeristy of the islamabad", "we are enjoying all the talent here at the city of atlanta", "what are you doing there" };
and a stopWords array i.e.
string[] stopWords = new string[] { " are ", " am ", " all ", " at ", " here ", " i ", " in ", " of ", " take ", " the ", " there ", " to ", " what ", " we ", " you " };
I have to replace stopWords in input_Text with " " (whiteSpace) but issue is that i am having " i " in stopWords array and text contains 'i' at start mean there is no whitespace at start of 'i'. So issue is the starting and ending word strings in text doesn't match with the stopWords, so unable to remove those words. The loop I'm using is....
for (int i = 0; i < input_Text.Count(); i++)
{
for (int j = 0; j < stopWords.Count(); j++)
{
input_Text[i] = input_Text[i].Replace(stopWords[j], " ");
}
}
Any suggestions will be highly appreciated.
Given your data, you can add a space character to the beginning and end of
input_Text
beforeReplace
, and remove them afterwards:Not very efficient, but should work fine.