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: 

Find string after certain position

0 Kudos

Dear Experts,

I have a string as follow

Data(v_string) = '12345***678**9'

I need to get the position of * after the number 8.

I cannot used:

FIND FIRST OCCURRENCE OF '*' in v_string match OFFSET pos

because it only return the position of the first * appearance which is the one after number 5.

I cannot use

SEARCH ... STARTING AT.... because it doesn't recognize *.

So is there away to do this?

Thanks

1 ACCEPTED SOLUTION

DoanManhQuynh
Active Contributor
0 Kudos

Then FIND ALL OCCURRENCES?

DATA(v_string) = '12345***678**9'.
DATA(_regex) = '[^\*]\*'.
FIND ALL OCCURRENCES OF REGEX _regex IN v_string RESULTS DATA(sub).
6 REPLIES 6

cdprasanna
Active Participant
0 Kudos

Hi,

First find the position of occurrence of the number(in your example 8). Then try fetching the next character using string offset.

Thanks.

0 Kudos

but the occurrence number is random not always eight,

even the length is also dynamic, it can be 1 to 100 but with two parts that consist of ****

0 Kudos

try some thing like below

DATA : lv_str TYPE string VALUE '123**34**',
       lv_offset TYPE i,
       lv_var1  TYPE string,
       lv_var2  TYPE string.

"now here i need to find the offset of * which is after 4
"sine i already know i need to find the occurence of * afetr 4 i will first devide it to two halfes and in second half  i will seacrh *

SPLIT lv_str AT '4' INTO lv_var1 lv_var2.
FIND FIRST OCCURRENCE OF '*' IN lv_var2 MATCH OFFSET lv_offset. 

thanga_prakash
Active Contributor

Hi Samuel Indrajaya Try with REGEX, it can be achievable with REGEX, refer to below blogs on how to use REGEX, refer to demo program DEMO_REGEX_TOY

REGEX Demo program DEMO_REGEX_TOY

REGEX in ABAP

DoanManhQuynh
Active Contributor
0 Kudos

Then FIND ALL OCCURRENCES?

DATA(v_string) = '12345***678**9'.
DATA(_regex) = '[^\*]\*'.
FIND ALL OCCURRENCES OF REGEX _regex IN v_string RESULTS DATA(sub).

Sandra_Rossi
Active Contributor

Basic algorithm question. Of course it's possible. I think it's possible in one statement if you use ABAP substring and find processing functions (see ABAP documentation).