Re: string plit
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Mon, 4 Sep 2006 06:18:13 +0200
Alan,
Therefore you have to find what character is at the end of each line. Not
tested but written in this message I think that I would do it something like
this to see what it is.
string myString = "Whatever";
int Lastcharacter = myString[myString.Count];
You should than get the charatcter at the last line of your string.
Than you can set that as a char in your split.
I hope this helps,
Cor
"Alan T" <alanpltseNOSPAM@xxxxxxxxxxxx> schreef in bericht
news:uL9a1W8zGHA.1268@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I almost can get my string split working, however, still got little
problem.
I got a text file in which a strange character, ie a little rectangle at
the end of each line. So when I call string split, I also got the little
rectangle with the word.
eg.
Hello world enquiry
After the split I got
Hello
world
enquiry
this is my code:
string fileText;
string[] keywords;
char[] charSeparators = new char[] { ' ', '\r', '\n', ',', '\t' };
try
{fileText = File.ReadAllText(aFile);
keywords = fileText.Split(charSeparators,
StringSplitOptions.RemoveEmptyEntries);
...
}
catch
{
}
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:O$FKdI$yGHA.480@xxxxxxxxxxxxxxxxxxxxxxx
Alan,
Why not try it yourself.
\\\
string myString = "What is \r\nthis";
char[] charSeparators = new char[] { ' ', '\r', '\n' };
string [] keywords = myString.Split(charSeparators,
StringSplitOptions.RemoveEmptyEntries);
foreach (string keyword in keywords)
{
MessageBox.Show(keyword);
}
///
I hope this helps,
Cor
"Alan T" <alanpltseNOSPAM@xxxxxxxxxxxx> schreef in bericht
news:%23MTZok%23yGHA.3704@xxxxxxxxxxxxxxxxxxxxxxx
string[] keywords;
char[] charSeparators = new char[] { ' ' };
keywords = aKeywords.Split(charSeparators,
StringSplitOptions.RemoveEmptyEntries);
foreach (string keyword in keywords)
{
MessageBox.Show(keyword);
_documentDA.DeleteDocumentKeyword(aDoc, keyword);
}
I can split the string into words if they are separated by a space.
How about if I have a string separated by space characters and return?
eg.
I entered "Hello world !" in the first line of a rich text box and press
"ENTER" key to the second line. Then enter "My name is Alan".
I just wonder the "!My" will be treated as one word.
.
- Follow-Ups:
- Re: string plit
- From: Alan T
- Re: string plit
- References:
- Re: string plit
- From: Alan T
- Re: string plit
- Prev by Date: Re: windows service path
- Next by Date: Re: Which controls can wrap line
- Previous by thread: Re: string plit
- Next by thread: Re: string plit
- Index(es):
Relevant Pages
|