-4

I have a string variable which stores the values of an URL like

"http://abc/abc_UAT/CustomerDetail.aspx?r=1".

I just need to search the character ? and need to store all character before '?' into another string variable

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • 2
    possible duplicate of [Get Substring - everything before certain char](http://stackoverflow.com/questions/1857513/get-substring-everything-before-certain-char) – Sayse Jul 27 '15 at 13:42
  • 1
    The given duplicate is the first result by searching for "c# string before char". Please do your own research and include it in your question if still need help – Sayse Jul 27 '15 at 13:42
  • You might consider using the Uri class to parse a URL: https://msdn.microsoft.com/en-us/library/system.uri(v=vs.110).aspx – Mark Peters Jul 27 '15 at 14:02

1 Answers1

-1

I will give you the answer even if this post is a duplicate.

You can use the Split function.

e.g. :

var before = "http://abc/abc_UAT/CustomerDetail.aspx?r=1";
var wantedString = before.Split('?')[0];
Ilshidur
  • 1,461
  • 14
  • 11
  • 2
    "I will give you the answer even if this post is a duplicate." - Please don't, while it may be tempting to get a quick reputation gain, its not great for the site in the long term since it can make it harder for people to search for material. (Plus it encourages people to post more bad questions) – Sayse Jul 27 '15 at 13:49
  • There isn't anything stopping you doing this, its just mine and a few others opinion of course... – Sayse Jul 27 '15 at 13:51
  • Actually for beginners it's really tough to find out the actual result by searching in site. I tried to do with Substring and indexOf like --------- string set1 = "http://abc/abc_UAT/CustomerDetail.aspx?r=1"; var res = set1.Substring(set1.IndexOf('?')); ------- but the result was "?r=1". – Rupam Routh Jul 29 '15 at 07:45
  • Split function solves my problem easily. Thank you so much. – Rupam Routh Jul 29 '15 at 07:51