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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:07:39+00:00 2026-05-21T16:07:39+00:00

I have several users and I would like to generate a referral url for

  • 0

I have several users and I would like to generate a referral url for each of them, but I don’t think it would be nice to have something like

http://domain.com/myusername

I would prefer to buy myself a shorten domain and transfor that myusernameinto something smaller, but not generated using the database so it would be easy to manage and no need to have a special table for this.

kinda like Dropbox does, as my referral is: http://db.tt/jnYosez

is there a simple way to change between a string into a short string and vice versa … or I can always use the User ID if I’m force to use numeric … maybe converting to other number base ?

Any idea is mostly appreciated 🙂

  • 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-21T16:07:39+00:00Added an answer on May 21, 2026 at 4:07 pm

    You can’t do it inhouse without using a database. It’s because the names are short and therefore it’s likely that a name have been used before.

    You need to generate a name (using randomness or an algorithm), check if it exists and then store it in the db.

    Update

    Here is a solution:

        public class NumberConverter
        {
            public const string HEX = "0123456789abcdef";
            public const string Bigger = "0123456789abcdefghihjklmnopqrstuvqyz";
            private int _numericBase;
            private string _base;
    
            public NumberConverter(string numberBase)
            {
                _base = numberBase;
                _numericBase = numberBase.Length;
            }
    
            public string ToString(int number)
            {
                var remainder = number % _numericBase;
                var div = number / _numericBase;
                string tmp = "";
                while (div > 0)
                {
                    tmp = _base[remainder] + tmp;
    
                    remainder = div % _numericBase;
                    div = div / _numericBase;
                }
                tmp = _base[remainder] + tmp;
    
                return tmp;
            }
    
            public int ToNumber(string numberString)
            {
                int index = numberString.Length - 1;
                int value = 0;
                int power = 0;
                while (index >= 0)
                {
                    char currentChar = numberString[index];
                    var currentValue = _base.IndexOf(currentChar);
                    value += currentValue * (int)Math.Pow(_numericBase, power);
                    power++;
                    --index;
                }
    
                return value;
            }
        }
    
    
    
        public static void Main()
        {
            var converter = new NumberConverter(NumberConverter.Bigger);
            int userId = 755757;
            var numberString = converter.ToString(userId); // prints g759
            var value = converter.ToNumber(numberString);
        }
    

    You can shorten the numbers even more by adding more that are allowed in uris.

    Theres probably a more efficient way to do it. Bitwise operations isn’t really my area.

    Update 2

    Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde.

      unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
    

    Which means that you can use those to shorten the url (unless your web server is using them for something else)

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

Sidebar

Related Questions

Problem I have a file which contains such text (nothing else) 2010-10-05 I would
I am learning RoR coming from many years of c# and MSSQL. I have
I have a page with a ScriptManager, a generic HTML drop-down list ( <select>
I have spent many hours working on this program that is supposed to play
I'm implementing a small voting system on my website. I came up with three
Summary: Trying to dynamically add heading rows to a ListView via a custom adapter
I hope this question makes sense. Basically, I am looking for a set of
I'm working on a webapp that uses SCORM so it can be included in
I'm working on a database heavy project, where the Microsoft SQL databases are very
I'm guessing this is a matter of figuring out what oracle command to use,

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.