C# Split Strings


Recommended Posts

ok I have this file I need to turn into an array so I can then use some numbers to set up a 3d array but that really does not matter

the files seams to be tab separated values along with carrage returns that need striped out.

I used this

(FYI tr = TextReader)

string[] Split = tr.ReadToEnd().Split(new char [] {'\t'});

I have also tried using a tabkey for the char

any ideals

note code is messy as I am testing different ideals

/*
* Created by SharpDevelop.
* User: huskeyw
* Date: 3/9/2007
* Time: 8:57 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;

using System.Collections.Generic;

using System.IO;



namespace file

{

class MainClass

{

public static void Main(string[] args)

{

string filenameWrite = "savdata.txt";

string filenameRead = "tldatanew.txt";



try

{

FileStream fs = new FileStream(filenameRead, FileMode.Open);

// FileStream fs2 = new FileStream(filenameWrite, FileMode.Append);

TextReader tr = new StreamReader(fs);

// TextWriter tw = new StreamWriter(fs2);
List<double> output = new List<double>();


try

{
string temp = "";
string[] Split = tr.ReadToEnd().Split(new char [] {'\t'});
for (int x = 0; x < Split.Length; x++)
{
Console.WriteLine(Split[x]);
temp += Split[x];
Console.ReadKey();
//temp = temp.Split(new char [] {'a', 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','%'});
//Console.WriteLine(temp);
}



}

finally

{

fs.Close();

//fs2.Close();

}

}

catch

{

Console.WriteLine("File not found");

}

Console.ReadKey();

}



}

}

file is attached

tldatanew.txt

Link to post
Share on other sites
Hmm. The attachment is space-separated values. Did the board eat the tabs?

hmm, I recived this from a diffrent company who states its tab seperted (which it seams since I did not check that it is spaces)

but seperating on spaces gives me wierd stuff like

100.003

insted of

100.00

3

here is the first couple

1.00
100.00
1.00
100.00
1.00
100.003
100.00
1.00
100.003
100.00
1.00
100.003
100.003
20.00
1.00
100.003
100.003
20.00
1.00
100.003
100.003
20.005000.00
1.00
100.003
100.003
20.005000.00
1.00
100.003
100.003
20.005000.00100

1.00
100.003
100.003
20.005000.00100

thanks for the help, it works great from the c++ program we are moving to c++

but it is vs 6 for c++, would that matter?

Link to post
Share on other sites
Hmm. The attachment is space-separated values. Did the board eat the tabs?

hmm, I recived this from a diffrent company who states its tab seperted (which it seams since I did not check that it is spaces)

but seperating on spaces gives me wierd stuff like

100.003

insted of

100.00

3

here is the first couple

1.00
100.00
1.00
100.00
1.00
100.003
100.00
1.00
100.003
100.00
1.00
100.003
100.003
20.00
1.00
100.003
100.003
20.00
1.00
100.003
100.003
20.005000.00
1.00
100.003
100.003
20.005000.00
1.00
100.003
100.003
20.005000.00100

1.00
100.003
100.003
20.005000.00100

thanks for the help, it works great from the c++ program we are moving to c++

but it is vs 6 for c++, would that matter?

sorry I got it, I had converted the entire thing to a single string insted of each line it own array segment, it works now..

sometimes my heads ends up in the wrong place.. :)

Link to post
Share on other sites

ok now how do I remove empty lines from the array I have?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...