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

  • Home
  • SEARCH
  • 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 806929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:19:21+00:00 2026-05-15T00:19:21+00:00

Is there any .Net library to remove all problematic characters of a string and

  • 0

Is there any .Net library to remove all problematic characters of a string and only leave alphanumeric, hyphen and underscore (or similar subset) in an intelligent way? This is for using in URLs, file names, etc.

I’m looking for something similar to stringex which can do the following:

A simple prelude

“simple English”.to_url =>
“simple-english”

“it’s nothing at all”.to_url =>
“its-nothing-at-all”

“rock & roll”.to_url =>
“rock-and-roll”

Let’s show off

“$12 worth of Ruby power”.to_url =>
“12-dollars-worth-of-ruby-power”

“10% off if you act now”.to_url =>
“10-percent-off-if-you-act-now”

You don’t even wanna trust Iconv for this next part

“kick it en Français”.to_url =>
“kick-it-en-francais”

“rock it Español style”.to_url =>
“rock-it-espanol-style”

“tell your readers 你好”.to_url =>
“tell-your-readers-ni-hao”

  • 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-05-15T00:19:21+00:00Added an answer on May 15, 2026 at 12:19 am

    I couldn’t find any library that does it, like in Ruby, so I ended writing my own method. This is it in case anyone cares:

    /// <summary>
    /// Turn a string into something that's URL and Google friendly.
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static string ForUrl(this string str) {
      return str.ForUrl(true);
    }
    public static string ForUrl(this string str, bool MakeLowerCase) {
      // Go to lowercase.
      if (MakeLowerCase) {
        str = str.ToLower();
      }
    
      // Replace accented characters for the closest ones:
      char[] from = "ÂÃÄÀÁÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöøùúûüýÿ".ToCharArray();
      char[] to = "AAAAAACEEEEIIIIDNOOOOOOUUUUYaaaaaaceeeeiiiidnoooooouuuuyy".ToCharArray();
      for (int i = 0; i < from.Length; i++) {
        str = str.Replace(from[i], to[i]);
      }
    
      // Thorn http://en.wikipedia.org/wiki/%C3%9E
      str = str.Replace("Þ", "TH");
      str = str.Replace("þ", "th");
    
      // Eszett http://en.wikipedia.org/wiki/%C3%9F
      str = str.Replace("ß", "ss");
    
      // AE http://en.wikipedia.org/wiki/%C3%86
      str = str.Replace("Æ", "AE");
      str = str.Replace("æ", "ae");
    
      // Esperanto http://en.wikipedia.org/wiki/Esperanto_orthography
      from = "ĈĜĤĴŜŬĉĝĥĵŝŭ".ToCharArray();
      to = "CXGXHXJXSXUXcxgxhxjxsxux".ToCharArray();
      for (int i = 0; i < from.Length; i++) {
        str = str.Replace(from[i].ToString(), "{0}{1}".Args(to[i*2], to[i*2+1]));
      }
    
      // Currencies.
      str = new Regex(@"([¢€£\$])([0-9\.,]+)").Replace(str, @"$2 $1");
      str = str.Replace("¢", "cents");
      str = str.Replace("€", "euros");
      str = str.Replace("£", "pounds");
      str = str.Replace("$", "dollars");
    
      // Ands
      str = str.Replace("&", " and ");
    
      // More aesthetically pleasing contractions
      str = str.Replace("'", "");
      str = str.Replace("’", "");
    
      // Except alphanumeric, everything else is a dash.
      str = new Regex(@"[^A-Za-z0-9-]").Replace(str, "-");
    
      // Remove dashes at the begining or end.
      str = str.Trim("-".ToCharArray());
    
      // Compact duplicated dashes.
      str = new Regex("-+").Replace(str, "-");
    
      // Let's url-encode just in case.
      return str.UrlEncode();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.