2

The string below contains two "?" what calculated column formula should I use to replace the second "?" with "&" but not remove the "?" from other strings that have only one "?"

Could anyone please provide the appropriate code to replace the second instance only of "?" in a string with a "&" ?

http://www.ipa.co.uk/cpd/coursedetails.aspx?courseid=275?utm_lead=pd&utm_format=qualification&utm_campaign=foundationcert17&utm_source=mailchimp&utm_medium=email
PhilFancy
  • 1,107
  • 1
  • 11
  • 29
user61554
  • 21
  • 4

2 Answers2

0

Use the following:

var index = input.IndexOf('?', input.IndexOf('?') + 1);
var ouput = string.Concat(input.Substring(0,index), "&", input.Substring(index + 1));

Or:

var output = new string(input.Select((c, i) => i == index ? '&' : c).ToArray());

Credit goes to: https://stackoverflow.com/questions/23547100/replace-second-occurence-of-with-an

Paul Strupeikis
  • 3,818
  • 4
  • 20
  • 33
0

Get it working Excel first, saves you SP headaches
You only need the basic functions, and the syntax in SharePoint Formulas is the same

Here is a list of functions that work in SharePoint Formulas: http://www.viewmaster365.com/365coach/#/Calculated_Column_Functions_List

Pseudo code:

  • Get the string after the first ?
  • In that string replace the ?

Note: SharePoint has no SUBSTITUTE function to replace all characters,
you can do it with nested functions:

StackOverflow: Calculated Column Formula how to replace Substitute

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79