Application Development and Automation 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: 
Read only

Find a '(' in a string?

Former Member
0 Likes
1,298

Hello,

I have the following code.


DATA: tmp TYPE STRING,
      result TYPE i.

tmp = 'Craig (Cmehil)'.
IF tmp CS '('.
  result = 1.
ENDIF.

write: / result.

IF tmp NS '('.
  result = 0.
ENDIF.

write: / result.

However the result should be 1 and then 0 but I get 1 and then 1 again.

How can I find the ( inside of a string?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
964

Hello Craig,

Use following statement. It works allways.

if ls_text CP '('.

do soething.

endif.

BR

Michael

6 REPLIES 6
Read only

Former Member
0 Likes
964

DATA: tmp TYPE STRING.

tmp = 'Craig (Cmehil)'.

write: / tmp.

IF tmp CA '#('.
  tmp = 'Found'.
ELSE.
  tmp = 'Not Found'.
ENDIF.

write: / tmp.

Sometimes sitting back and thinking and you get that whole apple on the head realization

Read only

0 Likes
964

Hi,

you can use SEARCH f FOR g to find string g in string f.

Regards,

Malgorzata

Message was edited by: Malgorzata Jaworek

Read only

Former Member
0 Likes
964

Hi,

you will not get a 1 in second case.

just think over again. what you are trying is in the first instance trying to see if the '(' is part of the string. which is yes, so it goes in ans set result to 1.

But in the second case you set result to 0 only when the string shouldn't contain '('. But since in your case it contains '(' it won't go in.

Read only

0 Likes
964

Actually the logic in the first post was completely wrong but my second post shows how I solved my own problem. Just didn't have my eyes open is all

Read only

Former Member
0 Likes
965

Hello Craig,

Use following statement. It works allways.

if ls_text CP '('.

do soething.

endif.

BR

Michael

Read only

0 Likes
964

Hi,

There is one more option, this will also work

IF char CN '+-*/=~#^[]\&%$@.,;:"!}{'.

-- do the job --

ENDIF

Prabhu Rajesh.