473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

string plit

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.
Aug 30 '06 #1
5 3066
Does new char[] {' ','\n', '\r', '\t'}; work?

Marc

Aug 30 '06 #2
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" <al*************@yahoo.com.auschreef in bericht
news:%2******************@TK2MSFTNGP02.phx.gbl...
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.


Aug 30 '06 #3
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]" <no************@planet.nlwrote in message
news:O$*************@TK2MSFTNGP06.phx.gbl...
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" <al*************@yahoo.com.auschreef in bericht
news:%2******************@TK2MSFTNGP02.phx.gbl...
>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.



Sep 4 '06 #4
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" <al*************@yahoo.com.auschreef in bericht
news:uL**************@TK2MSFTNGP02.phx.gbl...
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]" <no************@planet.nlwrote in message
news:O$*************@TK2MSFTNGP06.phx.gbl...
>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" <al*************@yahoo.com.auschreef in bericht
news:%2******************@TK2MSFTNGP02.phx.gbl. ..
>>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.




Sep 4 '06 #5
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 [MVP]" <no************@planet.nlwrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
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" <al*************@yahoo.com.auschreef in bericht
news:uL**************@TK2MSFTNGP02.phx.gbl...
>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]" <no************@planet.nlwrote in message
news:O$*************@TK2MSFTNGP06.phx.gbl...
>>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" <al*************@yahoo.com.auschreef in bericht
news:%2******************@TK2MSFTNGP02.phx.gbl.. .
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.




Sep 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
2
by: s | last post by:
I'm getting compile errors on the following code: <code> #include <iostream> #include <fstream> #include <list> #include <string> using namespace std;
2
by: jack | last post by:
Hello, I need to plit: "1,34,54,123,34" Into an array list. Thanks for any help, Jack
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.