convert string to string array

K

kvicky

I have multiline textbox and I am trying to do a search functionality
based on the input entered in this Textbox. I am able to convert into a
string array if the search components are separated by commas, for ex
(Image1, Image2) by using the StringArrayConverter class available in
..Net 2.0. But I also want to convert the strings entered in new line
for example if I enter

Image1
Image2

I want to convert this into a string array too, I used the split
funtcion but it takes null value between two strings If I don't pass
any delimiter.

Can anybody please help me with this.

Thanks
K
 
S

S Kachru

Try this...

string[] arr = s.Split(new char[] { '\n' });

where s is your string.

(I think split function takes in a character also, but my compiler is complaining...)
 
M

Michael Nemtsev

Hello kvicky,

I don't think that is the good approach to look substring
I recommend u to read this http://groups.google.com/group/micr...d418ab/eb5b783def1f282e?#doc_3ba155249e87e5e0

and see this http://groups.google.com/groups/search?q=dotnet+search+string

k> I have multiline textbox and I am trying to do a search functionality
k> based on the input entered in this Textbox. I am able to convert into
k> a string array if the search components are separated by commas, for
k> ex (Image1, Image2) by using the StringArrayConverter class available
k> in .Net 2.0. But I also want to convert the strings entered in new
k> line for example if I enter
k>
k> Image1
k> Image2
k> I want to convert this into a string array too, I used the split
k> funtcion but it takes null value between two strings If I don't pass
k> any delimiter.
k>
k> Can anybody please help me with this.
k>
k> Thanks
k> K
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
K

kvicky

Thanks...that worked and I used trim to remove the carriage return.

K

S said:
Try this...

string[] arr = s.Split(new char[] { '\n' });

where s is your string.

(I think split function takes in a character also, but my compiler is complaining...)

I have multiline textbox and I am trying to do a search functionality
based on the input entered in this Textbox. I am able to convert into
a string array if the search components are separated by commas, for
ex (Image1, Image2) by using the StringArrayConverter class available
in .Net 2.0. But I also want to convert the strings entered in new
line for example if I enter

Image1
Image2
I want to convert this into a string array too, I used the split
funtcion but it takes null value between two strings If I don't pass
any delimiter.

Can anybody please help me with this.

Thanks
K
 
M

Michael Nemtsev

Hello Ben,

there is description of how to search substrings, not the \n separator

BV> BV>BV> None of the methods mentioned in these articles will have any
BV> advantage when searching for a single character separator, in this
BV> case '\n'.
BV>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

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

Top