on 07-01-2010 10:25 PM
Hi All,
I would like to take a string formatted for a FormattedTextEdit and convert it for use in a TextEdit. This should have the same effect as if I highlighted all the contents of the FormattedTextEdit and pasted it into the TextEdit element (line breaks are preserved and other formatting is not).
My overall goal is to get SO10 texts into a TextEdit. Right now I've managed to get them into a FormattedTextEdit, so if there's a way to get the TextEdit formatting directly from SapScript texts, that would also be useful.
Thanks,
Scott
I don't think that is possible with TextEdit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I didn't find a standard way. This function covers most situations:
Note: add a semicolon ( to the end of each instance of  , ", and &. They won't display correctly here if left in.
FUNCTION Z_TEXT_FROM_FORMATTED_TEXT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(FORMATTEDTEXT) TYPE STRING
*" EXPORTING
*" REFERENCE(TEXT) TYPE STRING
*"----------------------------------------------------------------------
DATA: wa_text_in TYPE STRING,
wa_text TYPE STRING,
wa_inputlength TYPE I,
wa_strlen TYPE I,
wa_specialctr TYPE I,
wa_int TYPE I.
wa_text_in = FORMATTEDTEXT.
wa_inputlength = STRLEN( wa_text_in ).
WHILE wa_text_in IS NOT INITIAL.
IF SY-INDEX > wa_inputlength. "Emergency termination condition
EXIT.
ENDIF.
SPLIT wa_text_in AT '<' INTO wa_text wa_text_in.
"Find special characters
IF ( wa_text CS ' ' ) OR ( wa_text CS '"' ) OR ( wa_text CS '&' ).
wa_strlen = STRLEN( wa_text ).
wa_specialctr = 0.
WHILE wa_specialctr < wa_strlen.
ADD 1 TO wa_specialctr.
IF wa_text(wa_specialctr) CS ' '. "non-breaking space
wa_int = wa_specialctr - 6. "special character indicator length
CONCATENATE TEXT wa_text(wa_int) ' ' INTO TEXT.
wa_text = wa_text+wa_specialctr.
ELSEIF wa_text(wa_specialctr) CS '"'. "quote
wa_int = wa_specialctr - 6. "special character indicator length
CONCATENATE TEXT wa_text(wa_int) '"' INTO TEXT.
wa_text = wa_text+wa_specialctr.
ELSEIF wa_text(wa_specialctr) CS '&'. "ampersand
wa_int = wa_specialctr - 5. "special character indicator length
CONCATENATE TEXT wa_text(wa_int) '&' INTO TEXT.
wa_text = wa_text+wa_specialctr.
ENDIF.
IF wa_strlen <> STRLEN( wa_text ). "Reset for remainder of string when special character is found
wa_strlen = STRLEN( wa_text ).
wa_specialctr = 0.
ENDIF.
ENDWHILE.
ENDIF.
CONCATENATE TEXT wa_text INTO TEXT.
"Find HTML tags
wa_strlen = STRLEN( wa_text_in ).
IF wa_strlen >= 1. "Prevent crash
IF ( wa_text_in(1) CS 'p' ). "2 NewLines
CONCATENATE TEXT CL_ABAP_CHAR_UTILITIES=>NEWLINE CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TEXT.
ENDIF.
ENDIF.
IF wa_strlen >= 2. "Prevent crash
IF wa_text_in(2) CS 'br'. "Newline
CONCATENATE TEXT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TEXT.
ENDIF.
ENDIF.
SPLIT wa_text_in AT '>' INTO wa_text wa_text_in. "Throw away remainder of tag
ENDWHILE.
"Remove leading linebreaks
WHILE TEXT IS NOT INITIAL. "Prevent crash (out-of-bounds)
IF TEXT(1) = CL_ABAP_CHAR_UTILITIES=>NEWLINE.
TEXT = TEXT+1.
ELSE.
EXIT.
ENDIF.
ENDWHILE.
ENDFUNCTION.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.