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: 

Position of Character in a dynamically generated string

Former Member
0 Kudos

Hi all,

Can anyone tell me how I can find the position of the first character in a dynamically generated string, which has empty spaces preceding the 1st character.

For eg.,

" Hello World".

Here, the string Hello World is dynamic and in real time can be any string which the user might not know. In that case, how do I find out the position of the first character or find the number of spaces existing before I encounter the 1st character ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You can try this code..


DATA text(30).

text = '   My String'. "for example this is dynamic text

IF text CA sy-abcde OR text CA '0123456789'.
  WRITE : sy-fdpos.
ENDIF.

4 REPLIES 4

Former Member
0 Kudos

If u want to remove leading spaces, just use following statement:

SHIFT <fieldname> LEFT DELETING LEADING SPACES

Former Member
0 Kudos

You can try this code..


DATA text(30).

text = '   My String'. "for example this is dynamic text

IF text CA sy-abcde OR text CA '0123456789'.
  WRITE : sy-fdpos.
ENDIF.

Former Member
0 Kudos

Thank you all.

Former Member
0 Kudos

HI,

For searching the string u can use

SEARCH <c> FOR <str> <options>.

for deleting the preceeding r successing space

SHIFT <c> LEFT DELETING LEADING <str>.

SHIFT <c> RIGHT DELETING TRAILING <str>.

regards

zubair