6
votes
Accepted
Using String.replaceAll() to remove character combination
You could use replaceAll with a regular expression as follows:
url = url.replaceAll('-+','-');
This says "match one or more (+) hyphens (-)" and we replace it with the singular hyphen (-).
4
votes
Accepted
Replace function - SQL - Data Extension
Can likely use the TRIM(), LTRIM() or RTRIM() functions.
I vaguely remember that the more general TRIM() does not work in SFMC, so in this case you would want to use LTRIM().
For example, say you have ...
4
votes
Accepted
Regex to find dd/mm/yyyy
There are two issues:
replace(String target, String replacement) doesn't take a regExp as input, but a literal string.
You should have used replaceAll(String regExp, String replacement)
Strings are ...
4
votes
Accepted
Replacing text in lightning email template from apex
You shouldn't replace line breaks (\r\n) with <div> </div>, because that's semantically invalid HTML. Instead, you should split the lines by line break, and wrap them in <p>:...
2
votes
I need to replace white space to either side of a word
You probably want to use RegExMatch in your AMPscript. You want something like:
%%[
var @HeroProductTxt
var @pattern
var @match
set @HeroProductTxt = "whee t-shirt whoop"
set @pattern = &...
2
votes
Replace character in string in specific position (ie not first, not all)
Apex doesn't really support that. Strings are as in Java, immutable objects, so you can only create modified copies, but not update the original. It has to do with Java's String Pool. So, replaceFirst ...
2
votes
Accepted
Using replace() to remove a value from an array in LWC with a RegExp
Someone was kind enough to show me a pretty easy way to do this in JS:
@track myList = ['a', 'b', 'c'];
@track removeValue = 'b';
this.myList = this.myList.filter(value => value !== this....
2
votes
ReplaceAll does not function Apex
Strings are immutable. This means that all String functions return a new String value rather than modifying the String you called the method on, since a String cannot change. You need to capture those ...
2
votes
Accepted
Removing leading zeroes in Date String
If you really want a locally formatted date, you can use Date.parse and Date.format:
String shipDate = '04/06/2022';
System.debug(Date.parse(shipDate).format());
However, be aware that Date.parse ...
2
votes
How to update null records in JSON
Try something like this instead of manipulating the string directly:
Map<String, Object> data = (Map<String, Object>) JSON.deserializeUntyped(jsonResponse);
List<Object> matches = (...
1
vote
How to update null records in JSON
Do not manipulate the string. Deserialize it and remove the null from the list.
The first step is define a custom Apex class to map that response, then you can leverage typed deserialization, finally ...
1
vote
Apex replace \" in string
System.assertEquals(jsonString, 'Error fatal', 'Assertion failed');
Should be:
System.assertEquals('Error fatal', jsonString2, 'Assertion failed');
Because strings are immutable (cannot be changed), ...
1
vote
Replace double quotes in dataview Bounce
The three fields SMTPBounceReason, SMTPMessage and SMTPCode in the bounce data view are usual suspects to break your sql, because they can contain completely random stuff, including "A joke line ...
1
vote
Remove spaces and accents from a value field to put it in a From Email Adress field - dynamic sender profile
I would use a combination of AMP Script and SSJS to handle this. I would setup the workflow as follows:
Step 1) Get the Value
%%[
SET @accountname = AttributeValue("Opportunity:Account:Name&...
1
vote
Remove spaces and accents from a value field to put it in a From Email Adress field - dynamic sender profile
Honestly there is no simple solution here so it is gonna be a mess and far from efficient in AMPscript. Would be better to manipulate prior to send. Below is partial example on approach:
%%[
set @...
1
vote
Accepted
Modify string value in soql list and add back to list
You don't want to remove the commas, you just want to escape them properly. You'd also have problems with quote characters ("). Just do this:
getCustomerExport = [SELECT Customer_ID__c, Name from ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
replace × 19apex × 9
string × 6
replaceall × 6
regular-expressions × 5
marketing-cloud × 4
json × 4
escape × 2
visualforce × 1
lightning-web-components × 1
community × 1
ampscript × 1
email × 1
dataextensions × 1
controller × 1
email-template × 1
list × 1
sql × 1
datetime × 1
data × 1
singleemailmessage × 1
dynamic × 1
csv × 1
data-views × 1
array × 1