Remove leading characters from string ONLY if it is followed by a hyphen

heathers_
Kilo Sage

Hello,

How would I script removing all characters from a string ONLY if it is followed by a hyphen? I do not want the characters removed if the hyphen is not at the end. 

Example: hello- (should return null)

OR

hello (should return hello since there is not a hyphen)

 

Thanks!

 

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

For this example, our source column is called User ID, which is the equivilant of u_user_id. Feel free to change the source field to whatever the source field is for your import. Taking the function Michael used, I have created the script that you can use for the user_name target field (I am guessing that this is the target field):

answer = (function transformEntry(source) {
    var chkString = source.u_user_id.toString();
    if (chkString.endsWith('-D')){
        return '';
    } else {
        return chkString;
    }
})(source);

View solution in original post

6 REPLIES 6

ccajohnson
Kilo Sage

For this example, our source column is called User ID, which is the equivilant of u_user_id. Feel free to change the source field to whatever the source field is for your import. Taking the function Michael used, I have created the script that you can use for the user_name target field (I am guessing that this is the target field):

answer = (function transformEntry(source) {
    var chkString = source.u_user_id.toString();
    if (chkString.endsWith('-D')){
        return '';
    } else {
        return chkString;
    }
})(source);

Thanks all! This worked perfect.