|
-
Jun 11th, 2004, 06:12 PM
#1
simple -> how can I convert a multiline string to an array
I have a string with a bunch of "new line" characters. I want each line to be an element of a string array. I dunno what I'm doing wrong but it doesnt work too well with String.Split
I'm doign this:
String.Split (Environment.NewLine.ToCharArray());
every other element of the array appears to be blank (""). what's the right way?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jun 11th, 2004, 10:37 PM
#2
Sleep mode
I did this and it looks it's working .....
PHP Code:
System.IO.StreamReader sr=new System.IO.StreamReader("c:\\a.txt");
string[] ss =sr.ReadToEnd().Split(Environment.NewLine.ToCharArray());
foreach (string s in ss )
{
if (s !="")MessageBox.Show(s);
}
}
-
Jun 14th, 2004, 09:56 AM
#3
Frenzied Member
Try:
string[] keywordArray = keywordString.Split('\n');
DJ
-
Jun 14th, 2004, 09:57 AM
#4
Frenzied Member
Also you must remember that if there is more than one line return without any text they will still be split - which might be why some elements in the array are blank.
DJ
-
Jun 14th, 2004, 08:30 PM
#5
Evironment.Newline is equal to "\r\n" (assuming windows here), so your splitting by each element in the char array {'\r', '\n'}. So when you get a file like this:
line 1 \r\n
line 2 \r\n
you end up with the following:
line 1 (ends at \r)
null string (between \r and \n)
line 2 (ends at \r)
null string (between \r and \n)
Does that make sense?
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|