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

String validation

Former Member
0 Likes
1,092

hi, gurus,

i have a problem with a validation program for a text string S.

I want to validate that S starts with string A and ends with another string B.

Both A and B are the sets of different strings.

Is RegEX suitable for this program? Is there agile method to solve it?

Thanks,

xiongfei

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
802

Try this simple logic.

data: lv_str type string value 'ABCaasd;flkajsdf;lkasjXYZ'.
data: lv_begpt type string value 'ABC*'.
data: lv_endpt type string value '*XYZ'.

if lv_str CP lv_begpt
   and lv_str cp lv_endpt.
  write:/ 'String is valid'.
endif.

Regards,

Rich Heilman

3 REPLIES 3
Read only

former_member156446
Active Contributor
0 Likes
802

Hi Welcome to SDN..


vl_total = strlen ( S ).
vl_check = vl_total - 1.
if S+0(vl_total) CS A and if S+vl_check(vl_total) CS B.

Read only

RichHeilman
Developer Advocate
Developer Advocate
803

Try this simple logic.

data: lv_str type string value 'ABCaasd;flkajsdf;lkasjXYZ'.
data: lv_begpt type string value 'ABC*'.
data: lv_endpt type string value '*XYZ'.

if lv_str CP lv_begpt
   and lv_str cp lv_endpt.
  write:/ 'String is valid'.
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
802

Hi Xiongfei Zhao,

First Find the lenght of the String S using command STRLEN.

STRLEN is used to find the length of the string.

For example suppose the length of the string S is 14.

to find the first charecter use the OFFSET as shown below

data: lw_first type c,
      lw_last type c.

lw_first  = S+0(1).
lw_last = S+9(1).

Best regards,

raam