Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:10:59+00:00 2026-06-10T02:10:59+00:00

I want to add SuperScript to number in C# . Example: 1st, 2nd ……

  • 0

I want to add SuperScript to number in C#.

Example:

1st, 2nd ......

This i want to do dynamically in ASP.NET/C#

Please suggest best possible solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:11:01+00:00Added an answer on June 10, 2026 at 2:11 am

    Using the <sup> tag is the correct way to markup these values.

    this i want to do dynamically in asp.net c#

    If you have some knowledge of the locale, you could automatically add <sup> tags to text.

    Matching

    // this should go in a helper class
    
    // Obviously this depends on locale. The regex can be altered to accept numbers
    // with as many digits as desired. I think "th" is always an appropriate suffix
    // in English (not sure).
    private static readonly Regex _regex = new Regex( @"^(\d{1,8})(st|nd|rd|th)$", RegexOptions.Compiled );
    
    public static string AddSuper( string value ) {
        return _regex.Replace( value, "$1<sup>$2</sup>" );
    }
    

    Usage

    // in code-behind
    this.litMyText.Text = AddSuper( "1st" );
    
    // a few test cases (also demonstrates processing multiple items)
    
    // should match
    var testValues = new[] { "1st", "2nd", "10th", "20th", "1000th", "3rd", "19th" };
    
    foreach( string val in testValues ) {
        Response.Write( AddSuper( val ) );
    }
    
    // should not match
    testValues = new[] { "test", "nd", "fourth", "25", "hello world th", "15,things", "1 1 1thousand" };
    
    foreach( string val in testValues ) {
        Response.Write( AddSuper( val ) );
    }
    

    Output on Matched Values

    1<sup>st</sup>
    2<sup>nd</sup>
    10<sup>th</sup>
    20<sup>th</sup>
    1000<sup>th</sup>
    3<sup>rd</sup>
    19<sup>th</sup>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add my custom sidebar next right column all page. Please check this
I have a website built with ASP.NET (3.5) and want add some level of
When we want add a Number (for example 5) to all of excel worksheet
I want add new Feed item on entity persist and update. I write this
I want add user in ActiveDirectory. I use this code private SPUser CreateUser(string strLoginName,
I want add some methods. And this directive can't help me. var viewModel =
I want to add a class to a body tag with jQuery. For example
I have url, for example: http://i.myhost.com/myimage.jpg I want to change this url to http://i.myhost.com/myimage
I have 2 lists on one page - http://jsfiddle.net/nalsur/CneTJ/ And now I want add/create
Hello everyone I am completely stuck with this problem. I want add the name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.