The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,094 other followers

Archive for the ‘CSV’ Category

.NET/C#: Small class for double-quote escaping/unescaping (via StackOverflow)

Posted by jpluimers on 2013/09/10

Just came across this nice answer by harpo containing a small class that can Escape/Unescape double-quotes in strings.

–jeroen

via: Good CSV Writer for C#? – Stack Overflow.

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, CSV, Development, Software Development | Leave a Comment »

A Generalised and Comprehensive Solution to CSV to XML and XML to CSV Transformations – Pascaliburnus

Posted by jpluimers on 2013/02/21

Two interesting XSLTs:

  • XSLT to parse CSV into XML,
  • XSLT to transform XML to CSV

–jeroen

via: A Generalised and Comprehensive Solution to CSV to XML and XML to CSV Transformations – Pascaliburnus.

Posted in CSV, Development, Software Development, XML, XML/XSD, XSD, XSLT | Leave a Comment »

.NET/PowerShell: Get-Host, quick way to get CurrentCulture and CurrentUICulture

Posted by jpluimers on 2013/01/28

A quick and easy way of getting the CurrentCulture and CurrentUICulture is to use the get-host cmdlet from PowerShell.

This is what PowerShell 2.0 shows on my system:

C:\Users\jeroenp>powershell get-host

Name             : ConsoleHost
Version          : 2.0
InstanceId       : 1ce173fb-70a7-403b-a2bd-3800fe740f7c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-IE
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

The SeaTools from Seagate can’t cope with that because they don’t manage the Resource Fallback Process properly.

My machine is on en-IE, as it is English, and USA as location.

The main advantage for me is to use the that it is a good mix between English and Dutch settings:

  • English language (so you get proper error messages that you can find back using Google)
  • USA as location (to force more search engines to use .com domains)
  • EUR money settings (most software in Western Europe expects EUR, but displays USD when using en-US)
  • decimal dot (far easier import/export with non-Dutch stuff)
  • DD/MM/YYYY date format (I tried ISO 8601 YYYYMMDD, but that breaks too much software)
  • 24 hour clock format (just as it should be)
  • comma list separator (too much software is not configurable to use a certain separator for CSV, especially Excel depends on the system settings for list separator and decimal)
  • metric system (just as it should be)

–jeroen

via: Get-Host.

Posted in .NET, CSV, Development, Excel, ISO 8601, Office, Power User, PowerShell, Scripting, Software Development | Leave a Comment »

If you think CSV is easy; think again!

Posted by jpluimers on 2012/12/05

Lots of people think CSV is easy: it’s just a bunch of values separated with commas. But in practice it is not. Various reasons can make CSV very hard, especially since “CSV” is not a single, well-defined format. As always importing is always harder than exporting. A few reasons that make it hard:

A few links that helped me a lot getting input and output of CSV right in C#:

Thanks to Jabulaza:

–jeroen

via: Comma-separated values – Wikipedia, the free encyclopedia.

Posted in CSV, Development, Software Development | 4 Comments »

.NET/C#: SqlClient ConnectionString keys and their equivalences

Posted by jpluimers on 2012/11/07

A while ago I needed to shorten SqlClient ConnectionStrings. One way to do that is to use the shortest Key for each property (and not use the default key names that are much longer).

I beefed up the code to show you both the shortest and all equivalent keys (a few of the Microsoft exams want you to memorize most of these).

The HTML table below (similar to the huge and therefore hard to read table on MSDN) comes directly from the C# code at the bottom of the post. The only post-editing I did was making the header row bold.

Key ShortesEquivalentKey EquivalentKeys
Application Name app Application Name,app
ApplicationIntent ApplicationIntent ApplicationIntent
Asynchronous Processing async Asynchronous Processing,async
AttachDbFilename AttachDbFilename AttachDbFilename,extended properties,initial file name
Connect Timeout timeout Connect Timeout,connection timeout,timeout
Connection Reset Connection Reset Connection Reset
Context Connection Context Connection Context Connection
Current Language language Current Language,language
Data Source addr Data Source,addr,address,network address,server
Encrypt Encrypt Encrypt
Enlist Enlist Enlist
Failover Partner Failover Partner Failover Partner
Initial Catalog database Initial Catalog,database
Integrated Security trusted_connection Integrated Security,trusted_connection
Load Balance Timeout connection lifetime Load Balance Timeout,connection lifetime
Max Pool Size Max Pool Size Max Pool Size
Min Pool Size Min Pool Size Min Pool Size
MultipleActiveResultSets MultipleActiveResultSets MultipleActiveResultSets
MultiSubnetFailover MultiSubnetFailover MultiSubnetFailover
Network Library net Network Library,net,network
Packet Size Packet Size Packet Size
Password pwd Password,pwd
Persist Security Info persistsecurityinfo Persist Security Info,persistsecurityinfo
Pooling Pooling Pooling
Replication Replication Replication
Transaction Binding Transaction Binding Transaction Binding
TrustServerCertificate TrustServerCertificate TrustServerCertificate
Type System Version Type System Version Type System Version
User ID uid User ID,uid,user
User Instance User Instance User Instance
Workstation ID wsid Workstation ID,wsid

The code below uses a few techniques referenced as StackOverflow links:

  1. Sorting enumerable strings using LINQ.
  2. Generating CSV from an enumerable strings using LINQ and string.Join.
  3. Converting a DataTable to an HTML Table using an ASP.NET DataGrid and HtmlTextWriter to do the rendering.
  4. Getting a private static field by name using reflection.

Both the main program and the SqlConnectionStringBuilderHelper class are less than 70 lines of code (each about 50 when excluding comments and empty lines).

The SqlConnectionStringBuilderHelper uses the internals of the SqlConnectionStringBuilder class (all DbConnectionStringBuilder descendants I have seen work in a similar way):

  • each DbConnectionStringBuilder instance has a public Keys property that exposes the static _validKeywords field of the descendant. It contains all possible keys that can appear in a generated ConnectionString.
  • the SqlConnectionStringBuilder class (and other DbConnectionStringBuilder descendants) has a static private property _keywords that maps all possible keyword strings (including equivalents) to an enumerator (which indexes into the Keys property).
    Mono uses the same mechanism.
  • The trick is to walk the _keywords property and search for equivalent keywords.
  • For a list of equivalent keywords, you find the shortest one.

Related:

Enjoy the code: Read the rest of this entry »

Posted in .NET, ASP.NET, C#, C# 3.0, C# 4.0, C# 5.0, CSV, Development, LINQ, Software Development | Leave a Comment »

 
%d bloggers like this: