2007 Jun 11 2:18 PM
Hi there!
I need to translate tags in parentheses from lower to upper case. Is there a possibility to use regular expressions for this?
Be assured that points will be rewarded for useful answers.
Thanks!
Felix
2007 Jun 11 3:01 PM
The problem is that I don't know the content of the tags. I need to use regex for finding something between '<' and '>', and then translate the content found to upper case.
I would love to use something like
REPLACE ALL OCCURRENCES OF REGEX '\[([\]]+)\]([\[]+)\[end\]'
IN str_gaeb
WITH '<$1>$2</$1>'<b> USING UPPER CASE</b>.
But this doesn't exist...
2007 Jun 11 2:21 PM
Hi,
You can make use of translate statement.
data : str(10) type c value 'abcd'.
Translate str to upper case. "<-- output is ABCD
Regards
Sailaja.
2007 Jun 11 2:23 PM
Hi
try this.
Put all the data of expressions in an internal table ITAB, with single text field.
loop at ITAB.
translate itab-text+0(1) to Upper case
modify itab index sy-tabix.
endloop.
Reward points for useful Answers
Regards
Anji
2007 Jun 11 2:23 PM
2007 Jun 11 2:39 PM
Hi,
The TRANSLATE statement converts characters into upper or lower case, or uses substitution
rules to convert all occurrences of one character to another character.
Converting to Upper or Lower Case
TRANSLATE <c> TO UPPER CASE.
TRANSLATE <c> TO LOWER CASE.
These statements convert all lower case letters in the field <c> to upper case or vice versa.
Substituting Characters
TRANSLATE <c> USING <r>.
This statement replaces all characters in field <c> according to the substitution rule stored in field <r>. <r> contains pairs of letters, where the first letter of each pair is replaced by the second letter. <r> can be a variable.
For more variants of the TRANSLATE statement with more complex substitution rules, see the keyword documentation in the ABAP Editor.
Ex.
DATA: T(10) VALUE 'AbCdEfGhIj',
STRING LIKE T,
RULE(20) VALUE 'AxbXCydYEzfZ'.
STRING = T.
WRITE STRING.
TRANSLATE STRING TO UPPER CASE.
WRITE / STRING.
STRING = T.
TRANSLATE STRING TO LOWER CASE.
WRITE / STRING.
STRING = T.
TRANSLATE STRING USING RULE.
WRITE / STRING.
Output:
AbCdEfGhIj
ABCDEFGHIJ
abcdefghij
xXyYzZGhIj
Regards,
Bhaskar
2007 Jun 11 3:01 PM
The problem is that I don't know the content of the tags. I need to use regex for finding something between '<' and '>', and then translate the content found to upper case.
I would love to use something like
REPLACE ALL OCCURRENCES OF REGEX '\[([\]]+)\]([\[]+)\[end\]'
IN str_gaeb
WITH '<$1>$2</$1>'<b> USING UPPER CASE</b>.
But this doesn't exist...
2007 Jun 11 4:21 PM
Well, I don't pretend to be a RegEx expert by any means, but this is what I have come up with and I can safely say that I'm sure that there is a better way.
REPORT zrich_001.
DATA str(100) TYPE c.
DATA result_tab TYPE match_result_tab.
DATA result_lin LIKE LINE OF result_tab.
str = `This is a string(this needs to be upper case)`.
FIND ALL OCCURRENCES OF REGEX '([^(]*[^)])'
IN str RESULTS result_tab.
read table result_tab into result_lin index 2.
translate str+result_lin-offset(result_lin-length) to upper case.
write:/ str.
Regards,
Rich Heilman