locked
Cutting a string. RRS feed

  • Question

  • User-741660563 posted

    I have a string, "http://mydomain.com?id=22&p=value&last=true".  I would like to cut off "&last=true".  It is always at the end of the string, but in between the domain name and (&last=true) might be a different number of parameters, like

    http://mydomain.com?id=33&cat=cups&prod=1&last=true

    http://mydomain.com?id=42&cat=bags&prod=1&stag=false&last=true

    http://mydomain.com?id=98&cat=bags&subcat=kitchen&state=ca&last=true

    I would like to cut off &last=true each time.

     Thanks in advance!

     

    Tuesday, April 14, 2009 12:25 AM

Answers

  • User312496708 posted

    If you know exactly the the value &last=true need to be removed thanWhy dont you replace the string with emptystring

    strDmain.Replace("&last=true", "");

    This will remove the same in all case.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 14, 2009 1:01 AM

All replies

  • User312496708 posted

    If you know exactly the the value &last=true need to be removed thanWhy dont you replace the string with emptystring

    strDmain.Replace("&last=true", "");

    This will remove the same in all case.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 14, 2009 1:01 AM
  • User-741660563 posted

    Actually, I left out that the value of "last" can be different each time.  But you've got me started.  I can Replace &last with ^ and use Split ^ to get the first part.  Thanks!

     

     

    Tuesday, April 14, 2009 1:32 AM
  • User-40550723 posted

     Hi,

    You can use the following code.

     

     String aString = @"http://mydomain.com?id=33&cat=cups&prod=1&last=true";
     string[] arrString;
     arrString = aString.Split('&');
     string lastString = arrString[arrString.Length - 1];
     Response.Write("<BR/> " + lastString);
      
    Tuesday, April 14, 2009 2:03 AM