Introduction
This class helps the user to tokenize the Long string by specifying delimiter.
I thought this will be helpful to the programmers who are at beginning stage.
Code Listing
StringTokenizer::StringTokenizer(CString str,CString sep=" ")
{
index=0;
count=0;
CString str1="";
for (int i=0;i<str.GetLength() && sep.GetLength()==1;i++)
{
if(str.GetAt(i)==sep.GetAt(0))
{
elements.Add(str1);
str1="";
}
else
{
str1+=str.GetAt(i);
}
}
elements.Add(str1);
count=elements.GetSize ();
}
CString StringTokenizer::getNextElement()
{
index++;
if(index==count)
{
throw CString("Index out of Bounds");
}
return elements.GetAt(index-1);
}
int StringTokenizer::countElements()
{
return count;
}
CString StringTokenizer::elementAt(int index)
{
if(index>=count ||index<0)
{
throw CString("Index out of Bounds");
}
else
return elements.GetAt(index);
}