function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tinman44tinman44 

String HTML char from text field??

So here is my issue. I have some text fields that can store HTML formatted data in SFDC. For example "<strong>Test</strong>". What I need to do is get a character count of the non HTML characters in that field. So for our example I want to know that there is 5 char in it not 22 char.

 

I can do this in Javascript by using a regular expression:

 

var re= /<\S[^>]*>/g; var test = "<strong>Test</strong> test = test .replace(re,"");

 

But I woudl like to do it in APEX and store the char count in a field on that record. I am not Java guy so all the examples seem to drive me to have a beer. Can anyone point me in the right direction?  All I really need to know how to do is perform the above Javascript code in APEX...and I think I need to user the "replaceAll" method.

 

 

Thanks in advance!

 

jkljkl

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=19054

 

Public Static String getEmailFromSubjecct(String Subject){

// First, instantiate a new Pattern object "MyPattern"
String emailRegex = '(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*';
Pattern MyPattern = Pattern.compile(emailRegex);

// Then instantiate a new Matcher object "MyMatcher"
Matcher MyMatcher = MyPattern.matcher(Subject);

boolean hasMatch = MyMatcher.matches();
String match = MyMatcher.group(0);
return match;

}

 

prageethprageeth

I exactly can't guess what your purpose is. However I believe that following code will give you an idea.

If this is not what you are looking for, please supply more info and then I can help you.

 

public with sharing class LengthCounter{

public Integer getLength() {

Integer charCount = 0;

Pattern pat = Pattern.compile('<[^>]*>([^><]*)<.*');

Matcher matcherInstance = pat.Matcher('<strong>Test</strong>');

if (matcherInstance.find()) {

charCount = matcherInstance.group(1).length();

}

return charCount;

}