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: 

How to split the numeric and character in string?

Former Member
0 Kudos

Dear all

I have a problem with the split string to detach the numeric and character

For example:

Str1=u2019123.456 abcdu2019

I want the return value is u2018123.456u2019 ,removed the u2018abcdu2019

In this example the character u2018abcdu2019 maybe dynamic bits or value.

It can u2018abcu2019 or can u2018abcdeu2019 or can u2018abdu2019 etc..

How do to do it ?

Thanks

Sun

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

Are the letters always in the end? And starting in position 8? Or having the space between numbers and letters? This is usefull info that could allow us to give you the BEST solution.

However, I'll give you a generic solution that will allways work (I hope ).


DATA: lenght TYPE i,
      pos(2) TYPE n,
      str1   TYPE char255 VALUE '123.456 abcd'.
lenght = strlen( str1 ).
CLEAR pos.
DO lenght TIMES.
  IF NOT str1+pos(1) CO '0123456789.'.
    CLEAR str1+pos(1).
  ENDIF.
  ADD 1 TO pos.
ENDDO.
CONDENSE str1.

Regards.

Valter Oliveira.

9 REPLIES 9

Former Member
0 Kudos

Hi Sun,

str2 = str1(7).

Regards, Dieter

0 Kudos

will not work with "122.34 abcd"

0 Kudos

Hi Rainer,

sure, but has the value allways a lenght of 7 or does it has an dynamic lenght??

Do you know the answer?

regards, Dieter

Former Member
0 Kudos

data : var(10) type n,

var1(10) type c value '12.34VBFG'.

move var1 to var.

write var.

Former Member
0 Kudos

This message was moderated.

valter_oliveira
Active Contributor
0 Kudos

Are the letters always in the end? And starting in position 8? Or having the space between numbers and letters? This is usefull info that could allow us to give you the BEST solution.

However, I'll give you a generic solution that will allways work (I hope ).


DATA: lenght TYPE i,
      pos(2) TYPE n,
      str1   TYPE char255 VALUE '123.456 abcd'.
lenght = strlen( str1 ).
CLEAR pos.
DO lenght TIMES.
  IF NOT str1+pos(1) CO '0123456789.'.
    CLEAR str1+pos(1).
  ENDIF.
  ADD 1 TO pos.
ENDDO.
CONDENSE str1.

Regards.

Valter Oliveira.

0 Kudos

Congrats Valter. Good Solution. I appreciate your answer.

0 Kudos

Thanks for all.

the problem has solved.

Sun

Former Member
0 Kudos

Hi,

Try following code:

IF <field> CA sy-abcde.

length = sy-fdpos - 1.

string = <field>+0(leneth).

ENDIF.

Regards,

Kunjal