Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

translating from lower to upper case using regex

Former Member
0 Kudos
1,151

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
228

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...

6 REPLIES 6

Former Member
0 Kudos
228

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.

Former Member
0 Kudos
228

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

Former Member
0 Kudos
228

Hi Felix,

Try this,

TERM_TRANSLATE_TO_UPPER_CASE

Regards

Aneesh.

Former Member
0 Kudos
228

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

Former Member
0 Kudos
229

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...

0 Kudos
228

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