utils.stringReplace puzzle

I need to strip any HTML coding found in Field A and store the result in Field B. In other words, Field B should be just the text, no formatting.

I assumed the utils.stringReplace() function would be the place to start experimenting. However along the way I discovered this function will not support fields or variables, only hard coded text.

var vText = 'Some text to test';
globals.gutility1 = vText;
utils.stringReplace(vText, 'test', 'xxx');
globals.gutility2 = vText;

returns ‘Some text to test’. No change!!

However the following works fine:```
globals.gutility2 = utils.stringReplace(‘Some text to test’, ‘test’, ‘xxx’);


Anyone know of a method, a bean?, to strip HTML code and leave just the text? And what gives with uttils.stringReplace()?

I need to strip any HTML coding found in Field A and store the result in Field B. In other words, Field B should be just the text, no formatting.

var vTextToBeStripped = FieldA
vTextToBeStripped = utils.stringReplace(vTextToBeStripped , “”, “”) //removes html tag
FieldB = vTextToBeStripped

So this is not true.

However along the way I discovered this function will not support fields or variables, only hard coded text.

Fact remains that it seems pretty tedious to get rid of all html code.
(unless we’re talking about a limited and known set of html being used)

You can replace all tags with the following code but… It will replace everyting between ‘<’ and ‘>’ NOT making any difference between a real tag or some textual thing!

vText = vText.replace(/(<)(.)*?(>)/g,"")

regexpr rules :) thanks for sharing Marcel.

guys, guys, what about this one!

activitytext_plain = elements.activitytext.getAsPlainText();

That does it all!

:lol:

That looks like it is too simple :)

Can’t find it. 3.0?

no, it was there in 2.1.1 but suddenly disappears, but it still works!

Servoy Developer
Version R2 2.2.3-build 335
Java version 1.5.0_05-48 (Mac OS X - 10.4.3)

Hi Harjo,

I haven’t got a ‘,getAsPlainText()’ function under my elements node !? :cry:

Harry

Ah, just seen replies before mine - tried it under 2.2.3 and it does work !!!

Cheers Harjo !

Harry

You are just too slow Harry… May I advice you to buy new reading glasses or a screen with higher refresh rate :lol:

:lol: :lol: :lol:

pff, even for a servoyian it’s hard to keep up with all the features :oops:

Notice that getAsPlainText() will obviously only work on HTML RTF areas :)

Maarten, can you ask the dev-team why the function is not available anymore, but still works?

It should be there Harjo. (what version are you running?)
If not , then it’s a (displaying) bug
There’s no intention of removing this method.
I’m running 3.0a12 and it’s in there.

ah, now I see, it only appears on RTF or HTML-areas!
I was selecting a normal field.

Servoy Developer
Version R2 2.2.3-build 335
Java version 1.5.0_05-48 (Mac OS X)

Guilty as charged in not selecting a HTML area formatted field - so just to confirm that I do see it when selecting that type of field.

However, I also searched the help files and could not find a reference to it through contents, index or search - and, please note that I fully expect Marc to come back, point me to the exact location and tell me what a wally I am, here :slight_smile:

Cheers
Harry

Thanks everyone.

Harry Catharell:
Servoy Developer
Version R2 2.2.3-build 335
Java version 1.5.0_05-48 (Mac OS X)

Guilty as charged in not selecting a HTML area formatted field - so just to confirm that I do see it when selecting that type of field.

However, I also searched the help files and could not find a reference to it through contents, index or search - and, please note that I fully expect Marc to come back, point me to the exact location and tell me what a wally I am, here :-)

Cheers
Harry

Harry,

The pace and flurry of new features and functions in Servoy has been
so fast since the release of Servoy 2.2 (and its documentation release),
that we have not yet released the latest online, printed or PDF versions of
the documentation.

As a result, the functions and features in Servoy may not match the
version of the documentation you are using.

So, in this case, you are not being a wally :o


Marc Norman
Servoy