How do I know if my string contains a "micro" Unicode character?

I have an Excel spreadsheet with lab data that looks like this:

µg/L (ppb) 

I want to check the presence of the Greek letter "μ", and if found, I need to do something special.

Normally I would write something like this:

 if ( cell.StartsWith(matchSequence) ) { //.. <-- universal symbol for "magic" :) } 

I know that the Framework has an encoding API, but should I use it only for this edge or just copy the Greek microsymbol from the character map?

How can I check for the presence of this Unicode character? A character map seems like a “cheap” fix that will bite me later (I work for a company that is multinational).

I want to do something supported, and not just a crazy math-voodoo transform that only works for this case.

I think I'm asking for best practice advice here.

Thanks!

+3
source share
4 answers

You need to work out the Unicode character you need, then you can represent it in code with an escape sequence.

For example, μ is U + 00B5, so you just need to:

 if (text.Contains("\u00b5")) 

You can find out the Unicode value from charmap or from Unicode codes .

+12
source

The Unicode code point for micro μ is U + 00B5 and is different from the "Greek letter mu" μ, which is in U + 03BC. So you can use "\ u00b5" to find it, and perhaps also look for "\ u03bc" - they look the same, so anyone who created the table could use the wrong one!

+9
source

You can create a Char from the numerical equivalent displayed on the character map (displayed as U + 0050 for "P"). To do this, simply check the contents:

  string value; if (value.Contains(Char.ConvertFromUtf32(0x0050))) ; 
+1
source

C # code files are usually encoded in utf8, since the language uses this encoding. All strings and strict literals in C # (and other .NET languages) are encoded in utf16. This way you can safely copy the microsymbol from the character map. You can also use its integer value as a unicode literal, for example 0x1234.

0
source

All Articles