471,605 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Example code, String divided.

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[i]==wciecie)
{
return i;
}
if(litery[i]==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[i]==zamkniecie)
{
return i;
}
else if(litery[i]==wciecie)
{
return i;
}
else if(litery[i]==nastepny)
{
return i;
}
else if(litery[i]==omin)
{
return i;
}
else
{
word+=litery[i].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[i]==wciecie)
{
i=NextCharacter(i+1,litery,wciecie,Null)+1;
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==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[i]==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,re f wordy[n])+1;
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==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[i]==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,re f word)+1;
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==omin)
{
i++;
}
else
{
i=NextWord(i,litery,wciecie,wciecie,nastepny,omin, ref word);
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
}
return word;
}
}
}
pi*********@hotmail.com
Feb 6 '06 #1
2 1554
???

"PioM" <pi**@192.168.2.118> wrote in message
news:ds**********@atlantis.news.tpi.pl...
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[i]==wciecie)
{
return i;
}
if(litery[i]==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[i]==zamkniecie)
{
return i;
}
else if(litery[i]==wciecie)
{
return i;
}
else if(litery[i]==nastepny)
{
return i;
}
else if(litery[i]==omin)
{
return i;
}
else
{
word+=litery[i].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[i]==wciecie)
{
i=NextCharacter(i+1,litery,wciecie,Null)+1;
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==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[i]==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,re f wordy[n])+1;
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==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[i]==wciecie)
{
i=NextWord(i+1,litery,wciecie,wciecie,Null,Null,re f word)+1;
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
else if(litery[i]==nastepny)
{
i++;
}
else if(litery[i]==omin)
{
i++;
}
else
{
i=NextWord(i,litery,wciecie,wciecie,nastepny,omin, ref word);
if(n==numer)
{
return word;
}
else
{
word="";
}
n++;
}
}
return word;
}
}
}
pi*********@hotmail.com

Feb 6 '06 #2
PioM <pi**@192.168.2.118> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Jason | last post: by
11 posts views Thread by sethukr | last post: by
3 posts views Thread by =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post: by
3 posts views Thread by WP | last post: by
31 posts views Thread by somenath | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.