This is a migrated thread and some comments may be shown as answers.

Some way to perform a TrimAfterLast() in Fidder Script

3 Answers 228 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 04 Oct 2014, 09:23 PM
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

3 Answers, 1 is accepted

Sort by
0
Eric Lawrence
Telerik team
answered on 06 Oct 2014, 02:03 PM
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.

 
0
Kevin
Top achievements
Rank 1
answered on 08 Oct 2014, 01:11 PM
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;
0
Eric Lawrence
Telerik team
answered on 08 Oct 2014, 01:22 PM
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.

 
Tags
Fiddler Classic
Asked by
Kevin
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or