Extract a substring from a control's value

  • 22 January 2016
  • 0 replies
  • 37 views

  • Anonymous
  • 0 replies


 

Symptoms

 


Difficulty in extracting a substring from a control's value. The value will always begin with http://web/sites/. I want what's between the 4th slash and the last slash (including http:// slashes). An example of what I'm trying to do:

From the original string:
http://web/sites/project/number/one/doc.txt

Desired substring:
project/number/one
 

 

Diagnoses

 


This is not able to be done OOTB. There is a need to use javascript.
 

 

Resolution

Below is the javascript placed in an expression which resides in a Data Label.

<script> var input = "Parameter 1" var regex = //[a-zA-Z0-9]*[.][a-zA-Z0-9]*$/ input = input.replace('http://web/sites/','') input = input.replace(regex, '') document.getElementsByName("Data Label3")[0].innerHTML = input </script>

Parameter 1 is the parameter I created, and this value must be dragged and dropped from the context browser
Var regex is the regular expression which takes out everything after the last slash.
document.getElementsByName is the name of the Data Label that will house the expression. This is not a drag and drop value.

 

 



 

0 replies

Be the first to reply!

Reply