Hello
You can just scan your source string and collect long words. So, you will
need much more less memory, only for your long words.
private ArrayList FindLongWords(s tring source, int len)
{
int start = 0;
int currectPostion = 0;
int length = source.Length;
ArrayList longWords = new ArrayList();
// scan the source string
while (currectPostion < length)
{
// find next space
if (source[currectPostion] == ' ')
{
if (currectPostion - start >= len)
{
longWords.Add(s ource.Substring (start, currectPostion - start));
}
start = currectPostion + 1;
}
currectPostion ++;
}
if (currectPostion - start >= len)
{
longWords.Add(s ource.Substring (start, currectPostion - start));
}
return longWords;
}
--
With best regards,
Andrew
http://www.codeproject.com/script/pr...asp?id=1181072
"Howard" <ho*******@yaho o.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Can anyone think of a better algorithm for this function? Since longStr
could be very large in size (~100k).
The function will return a string array with words that are larger than
n in length. Where n is a positive integer.
string longStr = "asdfd DSFSDFSDFDSFASG DFD";
void FindLongWord(in t length)
{
string [] array;
array = longStr.split(' ');
for(int i =0;i < array.Length; i++)
{
if (array[i].Length >= length)
{
//add to arraylist...
}
}
}
Thanks,
Howard