Instead of: I;am;writing;in;C#
I want the output to be:
I
am
writing
in
C#
How and where can I edit the below code so that it can get rid of the ";" and put each word on a new line?
private ArrayList tokens;
private int currIndex;
private int numTokens;
private string currStr;
private string currDelimiter;
public StringTokeniser() {
}
public StringTokeniser(string text, string delimiter){
this.tokens = new ArrayList();
this.currStr = text;
this.currDelimiter = delimiter;
if(delimiter.Length == 0){
this.currDelimiter = " ";
}
this.Tokenize();
}
public StringTokeniser(string text, char[] delimiter) {
}
public StringTokeniser(string source) {
}
public string CurrStr{
get{
return this.currStr;
}
}
public string Delimiter{
get{
return this.currDelimiter;
}
}
private void Tokenize() {
string TempSource = this.currStr;
string Tok = "";
this.numTokens = 0;
this.tokens.Clear();
this.currIndex = 0;
if(TempSource.IndexOf(this.currDelimiter) < 0 && TempSource.Length > 0)
{
this.numTokens = 1;
this.currIndex = 0;
this.tokens.Add(TempSource);
this.tokens.TrimToSize();
TempSource = "";
}
else if(TempSource.IndexOf(this.currDelimiter) < 0 && TempSource.Length <=0)
{
this.numTokens = 0;
this.currIndex =0;
this.tokens.TrimToSize();
}
while(TempSource.IndexOf(this.currDelimiter) >= 0){
if(TempSource.IndexOf(this.currDelimiter) == 0)
{
if(TempSource.Length > this.currDelimiter.Length)
{
TempSource = TempSource.Substring(this.currDelimiter.Length);
}
else
{
TempSource = "";
}
}
else
{
Tok = TempSource.Substring(0,TempSource.IndexOf(this.currDelimiter));
this.tokens.Add(Tok);
if(TempSource.Length > (this.currDelimiter.Length + Tok.Length))
{
TempSource = TempSource.Substring(this.currDelimiter.Length + Tok.Length);
}
else
{
TempSource = "";
}
}
}
if(TempSource.Length > 0)
{
this.tokens.Add(TempSource);
}
this.tokens.TrimToSize();
this.numTokens = this.tokens.Count;
}
public void NewSource(string newSrc){
this.currStr = newSrc;
this.Tokenize();
}
public void NewDelim(string newDel)
{
if(newDel.Length == 0)
{
this.currDelimiter = " ";
}
else
{
this.currDelimiter = newDel;
}
this.Tokenize();
}
public void NewDelim(char[] newDel){
string temp = new String(newDel);
if(temp.Length == 0)
{
this.currDelimiter = " ";
}
else
{
this.currDelimiter = temp;
}
this.Tokenize();
}
public int CountTokens(){
return this.tokens.Count;
}
public bool HasMoreTokens(){
if(this.currIndex <= (this.tokens.Count - 1)){
return true;
} else{
return false;
}
}
public string NextToken() {
string result = "";
if(this.currIndex <= (this.tokens.Count - 1)) {
result = (string)tokens[currIndex];
this.currIndex++;
return result;
} else{
return null;
}
}
}
Hope someone can help. Thanks.
- Rukia
This post has been edited by skyhawk133: 21 December 2005 - 08:21 PM

New Topic/Question
Reply



MultiQuote



|