Example code, String divided.

  • Thread starter Thread starter PioM
  • Start date Start date
P

PioM

namespace System
{
public class Text
{
public static System.Char Omin='\t',Next='
',Wciecie='\"',Zamkniecie='\"',Null='\0',Object='ÿ';
public static System.Int32 NextCharacter(System.Int32 i,System.Char[]
litery,System.Char wciecie,System.Char nastepny)
{
for(;i<litery.Length;i++)
{
if(litery==wciecie)
{
return i;
}
if(litery==nastepny)
{
return i;
}
}
return i;
}
public static System.Int32 NextWord(System.Int32 i,System.Char[]
litery,System.Char wciecie,System.Char zamkniecie,System.Char
nastepny,System.Char omin,ref System.String word)
{
for(;i<litery.Length;i++)
{
if(litery==zamkniecie)
{
return i;
}
else if(litery==wciecie)
{
return i;
}
else if(litery==nastepny)
{
return i;
}
else if(litery==omin)
{
return i;
}
else
{
word+=litery.ToString();
}
}
return i;
}
public static System.Int32 PoliczWord2(System.String tekst,System.Char
wciecie,System.Char nastepny,System.Char omin)
{
System.Int32 i=0,n=0;
System.Char[] litery=tekst.ToCharArray();
while(i<litery.Length)
{
if(litery==wciecie)
{
i=NextCharacter(i+1,litery,wciecie,Null)+1;
n++;
}
else if(litery==nastepny)
{
i++;
}
else if(litery==omin)
{
i++;
}
else
{
i=NextCharacter(i,litery,wciecie,nastepny);
n++;
}
}
if(i==0)
{
return 0;
}
return n;
}
public static System.String[] Word2(System.String tekst,System.Char
wciecie,System.Char nastepny,System.Char omin)
{
System.String[] wordy=new
System.String[PoliczWord2(tekst,wciecie,nastepny,omin)];
System.Int32 i=0,n=0;
System.Char[] litery=tekst.ToCharArray();
while(i<litery.Length)
{
if(litery==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,ref wordy[n])+1;
n++;
}
else if(litery==nastepny)
{
i++;
}
else if(litery==omin)
{
i++;
}
else
{
i=NextWord(i,litery,wciecie,wciecie,nastepny,omin,ref wordy[n]);
n++;
}
}
return wordy;
}
public static int PoliczWord(System.String tekst)
{
return PoliczWord2(tekst,Wciecie,Next,Omin);
}
public static System.String[] WordFrom(System.String tekst)
{
return Word2(tekst,Wciecie,Next,Omin);
}
public static System.String Word(System.String tekst,System.Int32 numer)
{
System.String word="";
System.Int32 i=0,n=0;
System.Char[] litery=tekst.ToCharArray();
System.Char wciecie=Wciecie,nastepny=Next,omin=Omin;
while(i<litery.Length)
{
if(litery==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,ref word)+1;
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
else if(litery==nastepny)
{
i++;
}
else if(litery==omin)
{
i++;
}
else
{
i=NextWord(i,litery,wciecie,wciecie,nastepny,omin,ref word);
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
}
return word;
}
}
}
(e-mail address removed)
 
PioM said:
namespace System
{
public class Text

Aside from anything else (like the reason for the post) it's a bad idea
to start populating the System namespace yourself, and a *really* bad
idea to create a type called System.Text when there's already a
namespace with that name.

Now, did you have a question?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top