Delete Final comma in a html document

0
I have a situation where I have inherited an app where one of the letters is generated using html. It generates names and puts a comma after each one. The issue I have is that it puts a comma after the last name. I need to create something to delete or replace the final comma. Can you help?
asked
2 answers
1

Heey Timothy,

Maybe you can try something using replaceAll or replaceFirst as described here:

https://docs.mendix.com/refguide6/string-function-calls#replaceall

answered
0

Hi Timothy,

if you are certain that it always is and will be the last of the ‘,’ in the HTML and there can not be one after, you could create a custom java action with a string as input and a string as output.

public static String replaceLast(String string, String toReplace, String replacement) {
    int pos = string.lastIndexOf(toReplace);
    if (pos > -1) {
        return string.substring(0, pos)
             + replacement
             + string.substring(pos + toReplace.length(), string.length());
    } else {
        return string;
    }
}

 

from https://stackoverflow.com/questions/2282728/java-replacelast (there also is a version with regex)

 

otherwise you might want to look at pattern specifiers to apply above to the substring between the HTML tags (depending on how it looks like)

 

 

answered