Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:threadculture [2015/09/14] (current)
Line 1: Line 1:
 +====== Dealing with commas and periods ======
 +> **Developer:​** //​[[developer:​rhinocommon|RhinoCommon]]//​
 +> **Summary:​** //​Demonstrates how to consistently read/write numbers to strings.//
  
 +Depending on the user's culture settings, their computer may be set up to use commas instead of periods for decimal separators. This can cause problems when writing numbers into xml files and reading these xml files on a different culture setting.
 +
 +An easy way around this problem is to temporarily adjust the application'​s culture settings when reading/​writing files to always use a single culture.
 +
 +===== C# =====
 +<code c#>
 +// save current culture
 +System.Globalization.CultureInfo current_culture = System.Threading.Thread.CurrentThread.CurrentCulture;​
 +
 +// create and set english-us culture
 +System.Globalization.CultureInfo us_culture = new System.Globalization.CultureInfo("​en-us"​);​
 +System.Threading.Thread.CurrentThread.CurrentCulture = us_culture;
 +
 +int rc = WriteMyFile( filename );
 +
 +// restore the saved culture
 +System.Threading.Thread.CurrentThread.CurrentCulture = current_culture;​
 +</​code>​
 +
 +===== VB.NET =====
 +<code vb>
 +' save current culture
 +Dim current_culture As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
 +
 +' create and set english-us culture
 +Dim us_culture As new System.Globalization.CultureInfo("​en-us"​)
 +System.Threading.Thread.CurrentThread.CurrentCulture = us_culture
 +
 +Dim rc As Integer = WriteMyFile( filename )
 +
 +' restore the saved culture
 +System.Threading.Thread.CurrentThread.CurrentCulture = current_culture
 +
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
developer/sdksamples/threadculture.txt ยท Last modified: 2015/09/14 (external edit)