adesso orange🍊Stellenangebote:
Software Engineer Trainee · Senior
| (Senior) Cloud Software Engineer BTP
(Senior) Consultant Technologie · Consultant ABAP
Werkstudent Softwareentwicklung · Fiori / UI5 · Consulting · Application Management
FIND: Unterschied zwischen den Versionen
Aus SAP Wiki ツ
(Die Seite wurde neu angelegt: „Kategorie:Schlüsselbegriffe === Nützliche Seiten === * https://regex101.com/“) |
|||
Zeile 1: | Zeile 1: | ||
[[Kategorie:Schlüsselbegriffe]] | [[Kategorie:Schlüsselbegriffe]] | ||
=== REGEX === | |||
Beispiel: Alle Zeichen außer Buchstaben (a-z und A-Z), Zahlen (0-9), Punkt (.) und Leerzeichen entfernen | |||
<syntaxhighlight lang="abap" line start="1"> | |||
DATA: lv_invalid_chars, lv_invalid_char, lv_valid_char TYPE string. | |||
DATA: lc_space TYPE string VALUE ` `. "alt+255 (non breaking space) | |||
LOOP AT gt_csv_txt ASSIGNING FIELD-SYMBOL(<fs_csv_line>). | |||
FIND ALL OCCURRENCES OF REGEX '[^[:alnum:]\s\.]' IN <fs_csv_line> RESULTS DATA(it_invalid_chars). | |||
IF sy-subrc = 0. | |||
"we remove all found single chars in one step. | |||
LOOP AT it_invalid_chars INTO DATA(ls_invalid_chars). | |||
lv_invalid_char = <fs_csv_line>+ls_invalid_chars-offset(ls_invalid_chars-length). | |||
CASE lv_invalid_char. | |||
WHEN 'Á'. | |||
lv_valid_char = 'A'. | |||
WHEN 'É'. | |||
lv_valid_char = 'E'. | |||
WHEN 'Ó'. | |||
lv_valid_char = 'O'. | |||
WHEN 'Ü'. | |||
lv_valid_char = 'Ue'. | |||
WHEN 'Ä'. | |||
lv_valid_char = 'Au'. | |||
WHEN 'Ö'. | |||
lv_valid_char = 'Oe'. | |||
WHEN 'ä'. | |||
lv_valid_char = 'au'. | |||
WHEN 'ü'. | |||
lv_valid_char = 'ue'. | |||
WHEN 'ö'. | |||
lv_valid_char = 'oe'. | |||
WHEN 'á' OR 'ª'. | |||
lv_valid_char = 'a'. | |||
WHEN 'ß'. | |||
lv_valid_char = 'ss'. | |||
WHEN OTHERS. | |||
lv_valid_char = lc_space. | |||
ENDCASE. | |||
REPLACE SECTION OFFSET ls_invalid_chars-offset LENGTH ls_invalid_chars-length | |||
OF <fs_csv_line> WITH lv_valid_char. | |||
CLEAR lv_valid_char. | |||
ENDLOOP. | |||
ENDIF. | |||
ENDLOOP. | |||
</syntaxhighlight> | |||
=== Nützliche Seiten === | === Nützliche Seiten === | ||
* https://regex101.com/ | * https://regex101.com/ |
Version vom 29. November 2021, 12:06 Uhr
REGEX
Beispiel: Alle Zeichen außer Buchstaben (a-z und A-Z), Zahlen (0-9), Punkt (.) und Leerzeichen entfernen
DATA: lv_invalid_chars, lv_invalid_char, lv_valid_char TYPE string.
DATA: lc_space TYPE string VALUE ` `. "alt+255 (non breaking space)
LOOP AT gt_csv_txt ASSIGNING FIELD-SYMBOL(<fs_csv_line>).
FIND ALL OCCURRENCES OF REGEX '[^[:alnum:]\s\.]' IN <fs_csv_line> RESULTS DATA(it_invalid_chars).
IF sy-subrc = 0.
"we remove all found single chars in one step.
LOOP AT it_invalid_chars INTO DATA(ls_invalid_chars).
lv_invalid_char = <fs_csv_line>+ls_invalid_chars-offset(ls_invalid_chars-length).
CASE lv_invalid_char.
WHEN 'Á'.
lv_valid_char = 'A'.
WHEN 'É'.
lv_valid_char = 'E'.
WHEN 'Ó'.
lv_valid_char = 'O'.
WHEN 'Ü'.
lv_valid_char = 'Ue'.
WHEN 'Ä'.
lv_valid_char = 'Au'.
WHEN 'Ö'.
lv_valid_char = 'Oe'.
WHEN 'ä'.
lv_valid_char = 'au'.
WHEN 'ü'.
lv_valid_char = 'ue'.
WHEN 'ö'.
lv_valid_char = 'oe'.
WHEN 'á' OR 'ª'.
lv_valid_char = 'a'.
WHEN 'ß'.
lv_valid_char = 'ss'.
WHEN OTHERS.
lv_valid_char = lc_space.
ENDCASE.
REPLACE SECTION OFFSET ls_invalid_chars-offset LENGTH ls_invalid_chars-length
OF <fs_csv_line> WITH lv_valid_char.
CLEAR lv_valid_char.
ENDLOOP.
ENDIF.
ENDLOOP.