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 432013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:01:55+00:00 2026-05-12T20:01:55+00:00

Just wondering if you had any thoughts on this problem. I want to make

  • 0

Just wondering if you had any thoughts on this problem. I want to make it clear that this is for a coding DEMO. So this code is not ever going to become production code.

I would like to write a class which converts any of these URLs,

  1. http://www.google.co.nz
  2. http://WWW.google.co.nz
  3. google.co.nz
  4. http://google.co.nz

to this,

http://www.google.co.nz

So it should be ignoring what is on the start and concatinating http://www.

How would you suggest I do that? I have some logic which says stuff like this,

if (address.ToLower().Contains("http://"))
{
    address = address.ToLower().Replace("http://", "");
}
if (address.ToLower().Contains("www."))
{
    address = address.ToLower().Replace("www.", "");
}
address.Append("http://www.");

Any thoughts? How else could I solve this problem? Is there a regex that would help? Or would you solve it like I have above?

By the way this code is for a demo, so don’t ask why I would want this class.

  • 1 1 Answer
  • 1 View
  • 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-12T20:01:56+00:00Added an answer on May 12, 2026 at 8:01 pm

    The code you have now doesn’t handle https:// correctly and mangles urls that have www. in the middle of them (unlikely but possible). I would do it something like:

    string prefix = url.ToLower().StartsWith("https://") ? "https://www." : "http://www.";
    url = Regex.Replace(url, @"^((https?://)?(www\.)?)", prefix, RegexOptions.IgnoreCase);
    

    It is certainly possible to do it all in a single regular expression operation, but readability might suffer. And of course you should do the usual checking for string.IsNullOrEmpty etc.

    The System.Uri class might also have some interesting stuff you could use for this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Was just wondering if anyone had any simple ideas to do this. Effectively I'd
I was just wondering if anyone had any experience with more customized/specified theme rolling?
I'm just wondering if anyone has had any problems having too many subscribers for
I was just wondering if anyone had any success in getting XMLBeans (or any
Hey everyone, I was just wondering whether anybody had any experience with displaying svg
Was wondering if anyone had any thoughts on the use of Python's global vs.
Just wondering if anybody had the same problem with rubygems.org I appluad the decision
just wondering when I had an iphone I was able to create a web
just wondering if there is a way to reduce the amount of code needed
Just wondering, having the following simple code: var object1 = { name: function (){

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.