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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:13:58+00:00 2026-05-13T19:13:58+00:00

Can anyone help me how to optimize this method? public override VirtualPathData GetVirtualPath(RequestContext requestContext,

  • 0

Can anyone help me how to optimize this method?

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
    VirtualPathData path = base.GetVirtualPath(requestContext, values);

    if (path != null)
    {
        string virtualPath = path.VirtualPath;
        string condition = string.Empty;

        if (virtualPath.Contains("?"))
        {
            condition = virtualPath.Substring(virtualPath.IndexOf("?"));
            virtualPath = virtualPath.Substring(0, virtualPath.IndexOf("?"));
        }

        virtualPath = virtualPath.Replace(@"%C5%BD", "ž");
        virtualPath = virtualPath.Replace(@"%C4%90", "đ");
        virtualPath = virtualPath.Replace(@"%C4%86", "ć");
        virtualPath = virtualPath.Replace(@"%C4%8C", "č");
        virtualPath = virtualPath.Replace(@"%C5%A0", "š");

        virtualPath = virtualPath.ToLower().Replace(",", "-").Replace("%20", "-").Replace("&", "-");
        virtualPath = virtualPath.Replace(@"-amp;", "&");

        while (virtualPath.Contains("--"))
        {
            virtualPath = virtualPath.Replace("--", "-");
        }

        path.VirtualPath = virtualPath + condition;
    }

    return path;
}
  • 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-13T19:13:58+00:00Added an answer on May 13, 2026 at 7:13 pm

    In this code you are scanning the string three times for a character:

    if (virtualPath.Contains("?"))
    {
       condition = virtualPath.Substring(virtualPath.IndexOf("?"));
       virtualPath = virtualPath.Substring(0, virtualPath.IndexOf("?"));
    }
    

    Instead, scan it once and use the result three times. Also scan for a char instead of a string:

    int pos = virtualPath.IndexOf('?');
    if (pos != -1) {
       condition = virtualPath.Substring(pos);
       virtualPath = virtualPath.Substring(0, pos);
    }
    

    Here you are doing several replaces with the same replacement:

    virtualPath = virtualPath.ToLower().Replace(",", "-").Replace("%20", "-").Replace("&", "-");
    

    Instead you can use a regular expression to match all of them:

    virtualPath = Regex.Replace(virtualPath.ToLower(), "(,|%20|&)", "-");
    

    (Whether this actually gives better performance has to be tested with some of your actual data. Eventhough it’s less operations, there is some overhead in setting up the regular expresson.)


    You are using a loop to reduce clusters of characters:

    while (virtualPath.Contains("--"))
    {
       virtualPath = virtualPath.Replace("--", "-");
    }
    

    Instead you can use a regular expression to make a single replacement:

    virtualPath = Regex.Replace(virtualPath, "-{2,}", "-");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone one help me optimize this query SELECT `debit_side`.`account_code` CODE, GROUP_CONCAT(DISTINCT accounts.name) AS
can anyone can help me optimize this query and help me to tune my
Can anyone help - this is driving me mad. I am calling a mysql
Can anyone help me figure this out? The below code works fine and gets
Can anyone help me to convert this to proper JavaScript? <script>var datePostForAll = &#39;<div
Can anyone help me on how i can achieve this style for android ?
Can anyone help me trying to find out why this doesn't work. The brushes
Can anyone help me find an optimal Dynamic programming algorithm for this problem On
Can anyone help me with this CAML query? When I flip the Ascending attribute
Can anyone help me rewrite this query without a distinct clause? select a.rec_type ,

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.