Some way to perform a TrimAfterLast() in Fidder Script

4 posts, 0 answers
  1. Kevin
    Kevin avatar
    2 posts
    Member since:
    Oct 2014

    Posted 04 Oct 2014 Link to this post

    Hello,

    There is the very helpful Utilities.TrimBeforeLast() function in Fiddler script. However, I really need to perform a Utilities.TrimAFTERLast(StringVar, "}") to remove the extra characters after a JSON object i've captured. Is there any way I could produce this equivalent result with fiddlerscript?

    Thanks
    Kevin J
  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 06 Oct 2014 Link to this post

    Hi, Kevin--

    FiddlerScript allows you to use the entire .NET Framework, which offers many different functions for processing strings.

    In this case, you'd probably want to use something like:

      var sMyString = "whatever}junk";
      var iX = sMyString.LastIndexOf('}');
      sMyString = sMyString.Substring(0, iX);



    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Kevin
    Kevin avatar
    2 posts
    Member since:
    Oct 2014

    Posted 08 Oct 2014 in reply to Eric Lawrence Link to this post

    Thank you Eric, I forgot I can use any .net functions. 

    On a related note imported the System.Text.RegularExpressions class into the fiddlerscript rules to perform a regex match for the pattern "myData =", with zero or more spaces between the 'a' and '='. I can match 'myData ' , or 'myData =' as a fixed string no problem, but every time I try to use the "myData\s*=" pattern for an unknown amount of whitespace it does not match, though I know that is the correct regex pattern usually. Is there something else I need to do, like escape the '=' character,  for this to function in the fiddlerscript enviroment?

              
                    var RegExPattern = "myData\s*=";
                    var RegexResult = Regex.Match(oBody, RegExPattern, RegexOptions.IgnoreCase);
                    var objectStart = RegexResult.Index;
  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 08 Oct 2014 Link to this post

    Common mistake. :-)

    Remember, all of your strings are JavaScript strings. In JavaScript, you must escape the \ character inside a string to \\.

      var RegExPattern = "myData\\s*=";
     var RegexResult = Regex.Match(oBody, RegExPattern, RegexOptions.IgnoreCase);
     var objectStart = RegexResult.Index;


    Regards,
    Eric Lawrence
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top