string plit

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

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.
 
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
 
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 said:
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 said:
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.
 
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 said:
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 said:
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 said:
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.
 
Hi,

I think that little rectangle is a sort of non-Window thing, may like Linux
thing.
It appears as a little rectangle when I open the text file and using the
MessageBox.Show.

I think I cannot make it into
char[] charSeparators = new char[] { ' ', '\r', '\n', ',', '\t' };

Because there is no way to reproduce this little rectangle.

Cor Ligthert said:
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 said:
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 said:
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" <[email protected]> schreef in bericht
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.
 

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