c#中字符串显示上标和下标解决办法

时间:2021-05-03 17:56:37

  由于工作的需求,需要在word中插入带入带有上标和下标的字符串,比如这样的一个字符串:SO₄²⁻(mg/L)。在网上搜了好久,终是摸索出点思路。

  解决办法:使用转义字符加Unicode的HexEntity就可以实现了。比如定义一个SO₄²⁻(mg/L)这样的字符串如下:"SO\x2084\x00B2\x207B(mg/L)"。其中x2084为 ₄(注意:此处为4的下标) 的Unicode HexEntity,x00B2为 ²(注意:此处为2的上标) 的Unicode HexEntity,x207B为 ⁻(注意:此处为-的上标) 的Unicode HexEntity。

  

  一些常用字符如下:

Common Arithmetic & Alebgra

Character Name

Character Entity Num 
Entity
Hex 
Entity
LESS THAN < &lt; < <
GREATER THAN > &gt; > >
LESS THAN OR EQUAL TO &le;
GREATER THAN OR EQUAL TO &ge;
PLUS OR MINUS ± &plusmn; ± ±
NOT EQUALS &ne;
DIVISION SIGN ÷ &divide; ÷ ÷
TIMES X × &times; × ×
MINUS &minus;
DIVISION SLASH --
FRACTION SLASH &frasl
SQUARE ROOT RADICAL &radic;
CUBE ROOT -- &#x221B
FOURTH ROOT -- &#x221C
INFINITY &infin;
ALEF INFINITY SYMBOL &alefsym;
FUNCTION ITALIC F ƒ &fnof; ƒ ƒ
PRIME (single quote) &prime;
DOUBLE PRIME (double quote) &Prime;
TRIPLE PRIME (triple quote) --
THEREFORE (Triangular Dots) &there4;
DOT OPERATOR &sdot; &#x22C5
SUPERSCRIPT TWO ¹ &sup1; ¹ ¹
SUPERSCRIPT TWO ² &sup2; ² ²
SUPERSCRIPT THREE ³ &sup3; ³ ³
LEFT ANGLE BRACKET &lang;
RIGHT ANGLE BRACKET &rang;
LEFT CEILING BRACKET &lceil;
RIGHT CEILING BRACKET &rceil;
LEFT FLOOR BRACKET &lceil;
RIGHT FLOOR BRACKET &rceil;
CIRCLED PLUS (Direct Sum) &oplus; &#x2295
CIRCLED TIMES (Vector Product) &otimes; &#x2297

Superscript Chart(上标)

Character Name Character Num 
Entity
Hex 
Entity
SUPERSCRIPT ZERO &#x2070
SUPERSCRIPT ONE 
Entity Code = &sup1;
¹ ¹ &#x00B9
SUPERSCRIPT TWO 
Entity Code = &sup2;
² ² &#x00B2
SUPERSCRIPT THREE 
Entity Code = &sup3;
³ ³ &#x00B3
SUPERSCRIPT FOUR &#x2074
SUPERSCRIPT FIVE &#x2075
SUPERSCRIPT SIX &#x2076
SUPERSCRIPT SEVEN &#x2077
SUPERSCRIPT EIGHT &#x2078
SUPERSCRIPT NINE &#x2079
SUPERSCRIPT PLUS SIGN &#x207A
SUPERSCRIPT MINUS &#x207B
SUPERSCRIPT EQUALS SIGN &#x207C
SUPERSCRIPT LEFT PARENTHESIS &#x207D
SUPERSCRIPT RIGHT PARENTHESIS &#x207E
SUPERSCRIPT LATIN SMALL LETTER I &#x2071
SUPERSCRIPT LATIN SMALL LETTER N &#x207F

Subscript Codes(下标)

Character Name Character Num 
Entity
Hex 
Entity
SUBSCRIPT ZERO &#x2080
SUBSCRIPT ONE &#x2081
SUBSCRIPT TWO &#x2082
SUBSCRIPT THREE &#x2083
SUBSCRIPT FOUR &#x2084
SUBSCRIPT FIVE &#x2085
SUBSCRIPT SIX &#x2086
SUBSCRIPT SEVEN &#x2087
SUBSCRIPT EIGHT &#x2088
SUBSCRIPT NINE &#x2089
SUBSCRIPT PLUS SIGN &#x208A
SUBSCRIPT MINUS &#x208B
SUBSCRIPT EQUALS SIGN &#x208C
SUBSCRIPT LEFT PARENTHESIS &#x208D
SUBSCRIPT RIGHT PARENTHESIS &#x208E
LATIN SUBSCRIPT SMALL LETTER A &#x2090
LATIN SUBSCRIPT SMALL LETTER E &#x2091
LATIN SUBSCRIPT SMALL LETTER O &#x2092
LATIN SUBSCRIPT SMALL LETTER I &#x1D62
LATIN SUBSCRIPT SMALL LETTER R &#x1D63
LATIN SUBSCRIPT SMALL LETTER U &#x1D64
LATIN SUBSCRIPT SMALL LETTER V &#x1D65
LATIN SUBSCRIPT SMALL LETTER X &#x2093
GREEK SUBSCRIPT SMALL LETTER BETA &#x1D66
GREEK SUBSCRIPT SMALL LETTER GAMMA &#x1D67
GREEK SUBSCRIPT SMALL LETTER RHO &#x1D68
GREEK SUBSCRIPT SMALL LETTER PHI &#x1D69
GREEK SUBSCRIPT SMALL LETTER CHI &#x1D6A

Superscript and Subscript

Check these references for other methods to implement superscript/subscript and extra fractions

Fractions

These codes display fractions set to be all within one line with smaller number, but they can be replaced by other ways of typing a fraction (e.g. "1/2"). 
-- means no HTML entity code exists and that a numeric code must be used.

Character Name Character Entity Num 
Entity
Hex 
Entity
VULGAR FRACTION 1/4 ¼ &frac14; ¼ ¼
VULGAR FRACTION 1/2 ½ &frac12; ½ ½
VULGAR FRACTION 3/4 ¾ &frac34; ¾ ¾
VULGAR FRACTION 1/3 --
VULGAR FRACTION 2/3 --
VULGAR FRACTION 1/5 --
VULGAR FRACTION 2/5 --
VULGAR FRACTION 3/5 --
VULGAR FRACTION 4/5 --
VULGAR FRACTION 1/6 --
VULGAR FRACTION 5/6 --
VULGAR FRACTION 1/8 --
VULGAR FRACTION 3/8 --
VULGAR FRACTION 5/8 --
VULGAR FRACTION 7/8 --

Common Statistics

-- means no HTML entity code exists and that a numeric code must be used.

Character Name Character Entity Num 
Entity
Hex 
Entity
LOWER CASE MU (Mean) μ &mu; μ μ
LOWER CASE SIGMA (Standard Deviation) σ &sigma; σ σ
LOWER CASE CHI χ &chi; χ χ
CAPITAL PI N-ARY PRODUCT &prod;
N-ARY COPRODUCT (upside down capital pi) -- &#x2210

X-Bar, P-Hat and D-Bar

Some codes like that for  (X-bar) are actually a combination of two codes - the base letter x plus a code for the line above (&#772: or  ̄). Capital letter may need to be reduced in size to accomodate the placement of the combining diacritic.

Note on Safari: These symbols use combining characters and may not be correctly Safari 2 or other older browsers.

Statistical Symbol Codes
Character Name Character HTML Code
X-Bar (Average)
P-Hat
D-Bar <span style="font-size:80%">D</span>̄

Measurement Symbols

Common Symbols

Character Name Character Entity Num 
Entity
Hex 
Entity
DEGREE SYMBOL ° &deg; ° °
MICRO MU SYMBOL µ &micro; µ µ
SINGLE PRIME (feet, degree minutes) &prime; ߰
DOUBLE PRIME (feet, degree minutes) &Prime;c#中字符串显示上标和下标解决办法 ߰
PER MILLE (1/1000th) &permil; ߮

Calculus

Common Calculus Entity Codes

Character Name Character Entity Num 
Entity
Hex 
Entity
INTEGRAL &int;
PARTIAL DIFFERENTIAL &part;
INCREMENT (Difference or capital Delta) Δ &Delta; &#x2206
NABLA (Backward Difference, Grad or upside down triangle) &nabla; &#x2207

Additional Integral Symbols

These symbols have numeric entity codes only.

Character Name Character Num 
Entity
Hex 
Entity
DOUBLE INTEGRAL &#x222C
TRIPLE INTEGRAL &#x222D
QUADRUPLE INTEGRAL &#x2A0C
CONTOUR INTEGRAL &#x222E
SURFACE INTEGRAL &#x222F
VOLUME INTEGRAL &#x2230
CLOCKWISE INTEGRAL &#x2231
ANTICCLOCKWISE INTEGRAL &#x2A11
CLOCKWISE CONTOUR INTEGRAL &#x2232
ANTICLOCKWISE CONTOUR INTEGRAL &#x2233

Letter Symbols

Character Name Character Entity Num 
Entity
Hex 
Entity
INFINITY (Sideways 8) &infin;
ALEF INFINITY SYMBOL &alefsym;
WEIERSTRASS POWER SET (Script Capital P) &weierp;
IMAGINARY NUMBER (Blackletter I) &image;
REAL NUMBER (Blackletter I) &real;c#中字符串显示上标和下标解决办法
DOUBLE-STRUCK REAL NUMBER (Double R) --
COMPLEX NUMBERS (Double C) --
NATURAL NUMBERS (Double N) --
PRIME NUMBERS (Double P) --
RATIONAL NUMBERS (Double Q) --
INTEGERS (Double Z) --
Character Name Character Entity Num 
Entity
Hex 
Entity
FOR ALL (Upside-down A) &forall; &#x2200
COMPLEMENT (Thin C) -- &#x2201
THERE EXISTS (Backwards E) &exist; &#x2203
THERE DOES NOT EXIST (Backwards E with slash) -- &#x2204
EMPTY SET (O slash) &empty; &#x2205
NOT SYMBOL (Corner) ¬ &not; ¬ ¬
TILDE (Alternate Not Symbol) ˜ &tilde; -- --
LOGICAL AND (Wedge or Upside down V Symbol) &and; &#x2227
LOGICAL OR (V Symbol) &or; &#x2228
XOR -- &#x22BB
NAND -- &#x22BC
NOR -- &#x22BD
INTERSECTION (Cap or Upside Down U) &cap; &#x2229
UNION (Cup or U Symbol) &cup; &#x222A
ELEMENT OF &isin; &#x2208
NOT AN ELEMENT OF &notin; &#x2209
SMALL ELEMENT OF -- &#x220A
CONTAINS AS MEMBER &ni; &#x220B
DOES NOT CONTAIN AS MEMBER -- &#x220C
SMALL CONTAINS AS MEMBER -- &#x220D
SET MINUS -- &#x2216
SUBSET OF (Sideways U with cap to left) &sub; &#x2282
SUPERSET OF (Sideways U with cap to right) &sup; &#x2283
NOT A SUBSET OF (Subset with Slash) &nsub; &#x2284
NOT A SUPERSET OF (Superset with slash) -- &#x2285
SUBSET OF OR EQUAL TO (Subset with line below) &sube; &#x2286
SUPERSET OF OR EQUAL TO (Superset with line below) &supe; &#x2287
NEITHER A SUBSET OF NOR EQUAL TO -- &#x2288
NEITHER A SUPERSET OF NOR EQUAL TO -- &#x2289
SUBSET OF WITH NOT EQUAL TO -- &#x228A
SUPERSET OF WITH NOT EQUAL TO -- &#x228B
DIAMOND OPERATOR 
(Possibility)
-- &#x22C4
ASYMPTOTICALLY EQUAL TO 
One to one Correspondence
-- &#x2243
NOT ASYMPTOTICALLY EQUAL TO -- &#x2244
MULTISET (U with arrow) -- &#x228C
MULTISET MULTIPLICATION (U with dot in center) -- &#x228D
MULTISET UNION (U with plus in center) -- &#x228E
DOUBLE SUBSET -- &#x22D0
DOUBLE SUPERSET -- &#x22D1
DOUBLE INTERSECTION -- &#x22D2
DOUBLE UNION -- &#x22D3
N-ARY LOGICAL AND -- &#x22C0
N-ARY LOGICAL OR -- &#x22C1
N-ARY INTERSECTION&cu -- &#x22C2
N-ARY UNION -- &#x22C3
CURLY LOGICAL OR -- &#x22CE
CURLY LOGICAL AND -- &#x22CF
CIRCLED PLUS (Direct Sum) &oplus; &#x2295
CIRCLED TIMES (Vector Product) &otimes; &#x2297
CIRCLED MINUS -- &#x2296
CIRCLED DIVISION SLASH -- &#x2298

Other Element Of Symbols

ELEMENT OF WITH LONG HORIZONTAL STROKE &#x22F2
ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE &#x22F3
SMALL ELEMENT OF WITH VERTICAL BAR AT END OF HORIZONTAL STROKE &#x22F4
ELEMENT OF WITH DOT ABOVE &#x22F5
ELEMENT OF WITH OVERBAR &#x22F6
SMALL ELEMENT OF WITH OVERBAR &#x22F7
ELEMENT OF WITH UNDERBAR &#x22F8
ELEMENT OF WITH TWO HORIZONTAL STROKES &#x22F9
CONTAINS WITH LONG HORIZONTAL STROKE &#x22FA
CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE &#x22FB
SMALL CONTAINS WITH VERTICAL BAR AT END OF HORIZONTAL STROKE &#x22FC
CONTAINS WITH OVERBAR &#x22FD
SMALL CONTAINS WITH OVERBAR &#x22FE
NOTATION BAG MEMBERSHIP &#x22FF

Geometric Symbols

Note: The entity code for the Angle Symbol (∠) is &ang; and the code for the perpendicular angle (⊥) is&perp;
Otherwise, these symbols have numeric codes only.

Angles and Lines

Character Name Character Num 
Entity
Hex 
Entity
RIGHT ANGLE &#x221F
ANGLE 
Entity Code = &ang;
&#x2220
MEASURED ANGLE &#x2221
SPHERICAL ANGLE &#x2222
DIVIDES &#x2223
DOES NOT DIVIDE &#x2224
PARALLEL TO &#x2225
NOT PARALLEL TO &#x2226
RIGHT ANGLE WITH ARC &#x22BE
RIGHT TRIANGLE &#x22BF
UP TACK (Perpendicular) 
Entity Code = &perp;
&#x22A5
RIGHT TACK &#x22A2
LEFT TACK &#x22A3
DOWN TACK &#x22A4

Logical Proofs

Note: The entity code for the Therefore Symbol (∴) is &there4;. Otherwise, these symbols have numeric codes only.

Character Name Character Num 
Entity
Hex 
Entity
THEREFORE (Triangular Dots) 
Entity Code = &there4;
BECAUSE (Upside down Triangular Dots) &#x2235
PROPORTIONAL TO 
Entity Code = &prop;
&#x221D
END OF PROOF (solid rectangle) &#x220E

Common Equivalence and Proportion Operators

Common Equivalence Operators

Character Name Character Entity Num 
Entity
Hex 
Entity
NOT EQUALS &ne;
APPROXIMATELY EQUAL &cong;
ALMOST EQUAL (ASYMPTOTIC) &asymp;
NOT ALMOST EQUAL TO -- &#x2249
TILDE SIMILAR TO &sim;
IDENTICAL TO (three lines) &equiv;
NOT IDENTICAL TO -- &#x2262

Other Equivalence Symbols

STRICTLY EQUIVALENT TO &#x2263
NOT IDENTICAL TO &#x2262
LESS-THAN OVER EQUAL TO &#x2266
GREATER-THAN OVER EQUAL TO &#x2267
LESS-THAN BUT NOT EQUAL TO &#x2268
GREATER-THAN BUT NOT EQUAL TO &#x2269
MUCH LESS-THAN &#x226A
MUCH GREATER-THAN &#x226B
BETWEEN &#x226C
NOT EQUIVALENT TO &#x226D
NOT LESS-THAN &#x226E
NOT GREATER-THAN &#x226F
NEITHER LESS-THAN NOR EQUAL TO &#x2270
NEITHER GREATER-THAN NOR EQUAL TO &#x2271
LESS-THAN OR EQUIVALENT TO &#x2272
GREATER-THAN OR EQUIVALENT TO &#x2273
NEITHER LESS-THAN NOR EQUIVALENT TO &#x2274
NEITHER GREATER-THAN NOR EQUIVALENT TO &#x2275
LESS-THAN OR GREATER-THAN &#x2276
GREATER-THAN OR LESS-THAN &#x2277
NEITHER LESS-THAN NOR GREATERTHAN &#x2278
NEITHER GREATER-THAN NOR LESSTHAN &#x2279
NOT TILDE &#x2241
MINUS TILDE &#x2242
ASYMPTOTICALLY EQUAL TO &#x2243
NOT ASYMPTOTICALLY EQUAL TO &#x2244
APPROXIMATELY BUT NOT ACTUALLY EQUAL TO &#x2246
NEITHER APPROXIMATELY NOR ACTUALLY EQUAL TO &#x2247
NOT ALMOST EQUAL TO &#x2249
ALMOST EQUAL OR EQUAL TO &#x224A
TRIPLE TILDE &#x224B
ALL EQUAL TO &#x224C

Unicode对照表参考了: http://blog.csdn.net/snowdust/article/details/5895593