BestTechie Forums: C# Split Strings - BestTechie Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

C# Split Strings


#1 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 09 March 2007 - 04:08 PM

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

Attached File(s)



#2 User is offline   jcl 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1304
  • Joined: 30-August 04
  • Location:The Internet
  • Operating System:Arch

Posted 09 March 2007 - 09:32 PM

Hmm. The attachment is space-separated values. Did the board eat the tabs?

#3 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 09 March 2007 - 10:21 PM

View Postjcl, on Mar 10 2007, 02:32 AM, said:

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?

#4 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 09 March 2007 - 11:47 PM

View Posticcaros, on Mar 10 2007, 03:21 AM, said:

View Postjcl, on Mar 10 2007, 02:32 AM, said:

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.. :)

#5 User is offline   iccaros 

  • UberTechie
  • Group: Linux Experts
  • Posts: 1292
  • Joined: 31-August 04
  • Location:Great State of Washingtion
  • Operating System:Gentoo,Iccaros-Linux(of course),Slackware,GentooX,Red Hat, Windows (3.1 to VISTA BETA), MAC OSX (10.4 currently),LFS, Solaris 8,9,10, Trusted Solaris, FreeBSD, OPENBSD, NETBSD

Posted 10 March 2007 - 03:04 PM

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

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users