Quantcast
Channel: RLV Blog
Viewing all articles
Browse latest Browse all 79

Converting a CSV file to RegX with PowerShell

$
0
0

If you need to convert a CSV file with terms to a RegX file for use in your .Net project, you can use this simple PowerShell script:

$items = Import-Csv "C:\strings.csv" -Delimiter ',' -Encoding Default
[System.Resources.ResXResourceWriter]$resxWriter = New-Object System.Resources.ResXResourceWriter("c:\strings.resx")
$items | ForEach-Object { 
    $resxWriter.AddResource($_.Name, $_.Value);
}
$resxWriter.Close()

The script assumes your CSV file contains two columns, “Name” and “Value”, such as this:

Name,Value
MyString1,First value
MyString2,Second value
MyString3,Third value

You can use Excel to export such files. You may need to change the -Delimiter parameter in the script to match your locale (Why? See my post on working with CSV files in Excel).


Viewing all articles
Browse latest Browse all 79

Trending Articles