Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to create a tab delimited text file
Message
 
 
À
10/05/2010 11:28:05
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01463952
Message ID:
01463974
Vues:
38
So, how does your code solve the problem of outputting Data from SQL Server in Tab delimited format?

>>I'm assembling data from SQL server and VFP sources into a tab delimited txt file with 13 fields in it.
>>My current approach is to step thru the tables, populate 13 properties for each record and then assemble the properties with a writeline statement, separating each field with quotes and a tab character.
>>It seems kind of primitive after COPY TO x DELIMITED.
>>Is there a better way?
>
>
>You could write a reusable method that outputs a string with a variable number of parameters
>
>
>	class Test
>	{
>		//______________________________________________________________________
>		static void Main()
>		{
>			Console.WriteLine(ToTabDelimited("field1", "field2"));
>
>			Console.WriteLine(ToTabDelimited(1223, 456));
>			Console.WriteLine(ToTabDelimited("road 23", "88000", "San Diego"));
>
>			Console.ReadLine();
>
>		}
>		//______________________________________________________________________
>		static string ToTabDelimited(params object[] list)
>		{
>			StringBuilder sb = new StringBuilder();
>
>			for (var i = -1; ++i < list.Length; )
>			{
>				sb.AppendFormat("\"{{{0}}}\"\t", i);
>			}
>						
>			return String.Format(sb.ToString(0, sb.Length - 1), list);
>		}
>	}
>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform