Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sometimes the hard way is the most straightforward way. The Regex-based answers will return incorrect values for URLs that are not in the expected format.</p> <pre><code> static void Main(string[] args) { string inputString = @"https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?List=36caab7e%2D2234%2D4981%2D8225%%2Easpx"; //TEST CASES: //string inputString = @"https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?SomeParam=36caab7e%2D2234%2D4981%2D8225%%2Easpx"; //should return null //string inputString = @"https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?SomeParam=nih543&amp;List=786yui"; //should return https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?786 //string inputString = @"https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx?"; //should return null //string inputString = @"https://portal.test/sites/test/testabc/Lists/TEST/DispFormSort.aspx"; //should return null string result = GetShortenedListURL(inputString); Console.WriteLine(result); Console.ReadKey(); } private static string GetShortenedListURL(string InputString) { //Split URL into address and parameter tokens var tokens = InputString.Split('?'); if (tokens.Length &gt; 1) { var urlParams = tokens[1].Split('&amp;'); const string listStarter = "LIST="; //Loop through parameters looking for one that begins with List foreach (var param in urlParams) { if (param.ToUpperInvariant().StartsWith(listStarter)) { //Found the right parameter, now look for a contiguous string of numbers for (int numCounter = listStarter.Length; numCounter &lt; param.Length; numCounter++) { if (!Char.IsDigit(param[numCounter])) { if (numCounter &gt; listStarter.Length) { return tokens[0] + "?" + param.Substring(listStarter.Length, numCounter - listStarter.Length); } } } } } } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload