0

I'm new to salesforce/marketing cloud and have a hit a hurdle.

I have a text field looking like this Monday 10am - 12pm.

My question is, how can I remove the Day from this text using AmpScript?

Thanks and excited about this forum!

1 Answer 1

0

You can use IndexOf() and Substring() fucntions to get the desired string.

Option 1: Use " "(space) character to find the index.

%%[
var @textVar
Set @textVar = 'Monday 10am - 12pm'
var @tempIndex
Set @tempIndex = indexOf(@textVar,' ')
Output(v(@tempIndex))

var @subStringVar, @actualIndex
set @actualIndex = @tempIndex 
set @subStringVar = Substring(@textVar,@tempIndex,11)

Output(v(@subStringVar))
]%%

Option 2: Use "day" word to find the index.

%%[
var @textVar
Set @textVar = 'Monday 10am - 12pm'
var @tempIndex
Set @tempIndex = indexOf(@textVar,'day')
Output(v(@tempIndex))

var @subStringVar, @actualIndex
set @actualIndex = @tempIndex + 4 //because actual index will start after 4 characters from 'day
set @subStringVar = Substring(@textVar,@tempIndex,11)

Output(v(@subStringVar))
]%%

Please refer follwing links:

  1. Substing
  2. Replace

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .