Issue with text.replace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 04:56 AM
I am using a section of script added to a Script Include to convert the contents of an HTML field to a text field; to remove all HTML encoding characters. This is working really well, with one exception.
Anytime there is an apostrophe in the HTML text it is being converted to HTML in the text field. So, in the final text, instead of seeing an ' I'm getting '
Here is the script I am using to convert the text:
var text = demand.getValue("business_case").toString();
var regX = /(<([^>]+)>)/ig;
var finalText = text.replace(regX, " ");
project.setValue("description", finalText);
How best can I further modify this to insure any apostrophe is correctly rendered?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 05:07 AM
I had some similar exceptions with and such when importing info from Wikipedia and stripping out the HTML.
I generally address escaped/unicode characters like that with special cases one at a time (it makes it quite readable and maintainable.)
E.g.
var text1 = text.replace("':", "'");
FWIW, you don't need a toString() on the end of that first line. getValue() of a string field is going to return a string. You're effectively saying "turn this string in to a string." 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 05:10 AM
What fi you do this
var text = demand.getValue("business_case").toString();
var regX = /(<([^>]+)>)/ig;
var finalText = text.replace(regX, " ");
finalText = finalText.replace(''', "'");
project.setValue("description", finalText);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 05:22 AM
I ended up taking both of your replies and updating my script to the following:
var text = demand.getValue("business_case");
var regX = /(<([^>]+)>)/ig;
var finalText = text.replace(regX, " ");
finalText = finalText.replace("'", "'");
project.setValue("description", finalText);
Which now works well and no more weird characters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2022 06:15 AM
But, it is replacing at first time, if it is repeated , it's not.
is there any fix to replace for multiple times on the special character in the description like "@", "+"