2008 Jan 18 9:13 AM
Hi all,
Consider the string ,
" Hello World"
where the space before the letter H in Hello are empty character spaces. Can anyone tell me how I can find the position of the letter H from the beginning of the sentence using String processing ?
Thank you.
2008 Jan 18 9:24 AM
Hi Ezhil,
DATA:
zlv_offset type i,
zlv_test type string value ' Hello World'.
find FIRST OCCURRENCE OF 'H' in zlv_test match OFFSET zlv_offset.
write zlv_offset.
Kind regads,
John.
hi,
SEARCH string FOR 'H'.
sy-fdpos will tell you where is it in the string.
ec
2008 Jan 18 9:18 AM
Hi,
Use search
for example.
search space in string.
if sy-subrc eq 0.
w_counter = sy-fdpos + 1.
endif.
write: w_counter.
w_counter gives the position.
Plzz reward points if it helps.
2008 Jan 18 9:19 AM
hi,
SEARCH string FOR 'H'.
sy-fdpos will tell you where is it in the string.
ec
2008 Jan 18 9:21 AM
it can be done like this:
lf_string = ' Hello World'.
IF lf_string CA 'H'.
"here, SY-FDPOS contains the position of the letter "H", in this case 2
ENDIF.Greetings
Thomas
2008 Jan 18 9:24 AM
Hi Ezhil,
DATA:
zlv_offset type i,
zlv_test type string value ' Hello World'.
find FIRST OCCURRENCE OF 'H' in zlv_test match OFFSET zlv_offset.
write zlv_offset.
Kind regads,
John.
2008 Jan 18 9:25 AM
Hi,
Use SY-FDPOS system variable to find out the position of string.
SY-FDPOS
Location of hit in string operations.
When you use CO,CN, CA, NA, CS, NS, CP, and NP, offset values are assigned to SYFDPOS
depending on the search result.
SEARCH FOR sets SY-FDPOS to the offset of the search string.
Example:
DATA: STRING(30) VALUE 'This is a fast first example.',
POS TYPE I,
OFF TYPE I.
WRITE / STRING.
SEARCH STRING FOR 'ft' ABBREVIATED.
WRITE: / 'SY-FDPOS:', SY-FDPOS.
POS = SY-FDPOS + 2.
SEARCH STRING FOR 'ft' ABBREVIATED STARTING AT POS AND MARK.
WRITE / STRING.
WRITE: / 'SY-FDPOS:', SY-FDPOS.
OFF = POS + SY-FDPOS -1.
WRITE: / 'Off:', OFF.
Regards,
Bhaskar
2008 Jan 18 9:25 AM
DATA text(30) value ' Hello world'.
SEARCH text FOR 'H'.
WRITE SY-FDPOS. "your case it returns 1
2008 Jan 18 9:27 AM
hi,
This code below will help you to find the position of a character in a string.
PARAMETERS: INPUT(30) TYPE C,
FIND(1) TYPE C.
SEARCH INPUT FOR FIND.
IF SY-SUBRC = 0.
WRITE : 'CHAR FOUND'.
WRITE : SY-FDPOS.
ELSE.
WRITE : 'CHAR NOT FOUND'.
ENDIF.
Reward points if useful.
2008 Jan 18 9:33 AM
2008 Jan 18 9:37 AM
But I would also like to know how I can find the position of the character in the string if the String is dynamically generated. Can anyone throw some light on this ?
2008 Jan 18 9:43 AM
Hi,
In dynamic string also use search only.
for example
DATA: text TYPE string VALUE `Roll over Beethoven`,
pos TYPE i.
SEARCH text FOR '. .'.
SEARCH text FOR ` `.
IF sy-subrc = 0.
pos = sy-fdpos + 2.
SEARCH text FOR 'bth' STARTING AT pos
ABBREVIATED AND MARK.
ENDIF.
Plzz reward points if it helps.
2008 Jan 18 9:46 AM
data: str type string .
data: l type i,
counter type i.
str = ' Hello World'.
l = strlen( str ).
write: l.
search str for 'H'.
if sy-subrc = 0.
counter = sy-fdpos + 1.
endif.
write: counter.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |