Home > Back-end >  c# append slash to the path parameter
c# append slash to the path parameter

Time:03-03

I need to add dot (.) in path parameter and it turns out that dot will only work if we append a / slash at the end of that parameter.

For example: /api/path.param/?q=123 this will work

However: /api/path.param?q=123 wont work without the trailing slash

I was hoping to programmatically add the slash / if the query parameter is q=123.

How can this be done in MVC 4?

CodePudding user response:

If the /api/path.param is always the same you could use (the hack-y method):

variable_name = variable_name.Substring(0, 15)   "/"   variable_name.Substring(15);

If it isn't always the same you could do (the more dynamic method):

int index = variable_name.IndexOf("?q=");
variable_name = variable_name.Substring(0, index)   "/"   variable_name.Substring(index);
  • Related