Remove text from string until it reaches a certain character

后端 未结 4 2108
忘掉有多难
忘掉有多难 2021-01-17 12:26

I\'m having a issue trying to figure out this. I need to \"fix\" some links, here is an example:

  1. www.site.com/link/index.php?REMOVETHISHERE
  2. www.site.c
4条回答
  •  梦谈多话
    2021-01-17 13:00

    To remove last "?" and everything after it:

        string input = @"www.site.com/link/index.php?REMOVETHISHERE";
        input = input.Remove(input.LastIndexOf('?'));
    
        OR
    
        string input = @"www.site.com/link/index.php?REMOVETHISHERE";
        input = input.Substring(0, input.LastIndexOf('?'));
    

    Now the output will be:

    www.site.com/link/index.php
    

提交回复
热议问题