Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

 

Highlight a phrase and click this icon to search it on Swyx-Forum   Highlight a phrase and click this icon to search it within the Swyx Knowledgebase   Highlight a phrase and click this icon to search it using Goolge   Highlight a phrase and click this icon to search it using Wikipedia

List of Blogs
Search Blogs
Blog Archive

Most recent blog entries

 

Most recent blog entries

 

Jan21

Written by:Martin
21.01.2010 20:13 

What’s the output of this c# code? Is the result always the same?

string s = "I";
Console.WriteLine(s.ToLower());

It outputs letter “I” in lower case.

i

But not always. Switch your Windows user’s regional settings to Turkish and the same code will output this:

ı

It’s a lower-case “i” without the dot. The Turkish language has two kinds of “i”, one with the dot, one without. The small “i” has an upper-case pendant, too:

İ

You might think if that has anything to do with SwyxWare? It has. Last week I got a question from one of my pre-sales support colleagues. A customer observed that SwyxIt! would not login when the Windows user has Turkish regional settings. Today I finally got trace files from SwyxIt! and could narrow down the location of the failure. There is a condition in SwyxIt! similar to this:

if (s.ToLower().StartsWith("i"))

Unfortunately the string checked in this statement starts with an upper-case “I”. The expression returns false for Turkish regional settings and true if you use English or German or almost any other language setting. In this case the fix is easy:

if (s.ToLower(CultureInfo.InvariantCulture).StartsWith("i"))

Using InvariantCulture is correct in this case, but other scenarios might needs a different approach.

 

 

Tags:

 

2 comment(s) so far...

Re: ToLower()

Schöner finde ich:
if (s.StartsWith("i", StringComparison.InvariantCulture))

Vielleicht geht sogar sowas?

if (s.StartsWith("i", StringComparison.InvariantCulture | StringComparison.OrdinalIgnoreCase))
(Weiß nicht, ob man das mit | verknüpfen kann?!)

By Frank Schmidt on  21.01.2010 20:37

Re: ToLower()

StringComparison.InvariantCultureIgnoreCase sollte gehen. Und ja, deine Variante ist schöner :-)

By Martin on  21.01.2010 20:40

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
Blog Help
Sponsors
UCIT cloud communication
IPIT Ltd
bluvo AG
logic-base GmbH
Atia Communications

 

 

logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de
logic-base GmbH
www.logic-base.de
Atia Communications
www.atiacomms.com
UCIT Nordic
www.ucit.no
IPIT Ltd
www.ipit.co.uk
bluvo AG
www.bluvo.de