‎2010 Feb 23 9:02 AM
Hi Experts,
I have a requirement to take first 10 characters of a string including spaces and numbers but eliminating punctuations marks.
So can someone please help me with the punctuation part i.e is there a way to include all punctuations or do i have to write explicitly all of them.
Thanks in anticipation.
‎2010 Feb 23 9:11 AM
First of all welcome to SDN and please read the engagement rules ..
Do search before posting such basic questions
Still i am giving you this code .. Not exactly what you want .. but i am sure you can tweak it to your requirements ..
REPORT zstring.
DATA : ipstr TYPE string.
DATA : opstr TYPE string.
DATA : len TYPE i VALUE 0.
DATA : ch TYPE char1.
DATA : num TYPE i VALUE 0. "No of Characters to be taken
DATA : pos TYPE char3. "Position of Char in the Input String
*Input string
ipstr = '<FT><H><T> Line Clearance </></></>'.
*Removing only "</>"
REPLACE ALL OCCURRENCES OF '</>' IN ipstr WITH ' '.
*Removing only "<"
REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '.
CONDENSE ipstr.
*Length of Input String
len = STRLEN( ipstr ).
DO len TIMES.
*Char by Char
ch = ipstr+pos(1).
pos = pos + 1.
*Scan each char in input String for ">"
FIND '>' IN ch IGNORING CASE.
IF sy-subrc = 0.
num = len - pos.
*Output String
opstr = ipstr+pos(num).
ENDIF.
ENDDO.
WRITE :/ opstr.
This will help you to modify any type of strings .. in the code i have pasted it removes HTML tags .. instead of that just give the punctuation marks ..
Hope this answer helps you
Regards ..
Manthan
‎2010 Feb 23 9:07 AM
Suppose
L_STR = ' 123456789'.
then do like this...
L_str1 = l_str+0(10).
‎2010 Feb 23 9:11 AM
First of all welcome to SDN and please read the engagement rules ..
Do search before posting such basic questions
Still i am giving you this code .. Not exactly what you want .. but i am sure you can tweak it to your requirements ..
REPORT zstring.
DATA : ipstr TYPE string.
DATA : opstr TYPE string.
DATA : len TYPE i VALUE 0.
DATA : ch TYPE char1.
DATA : num TYPE i VALUE 0. "No of Characters to be taken
DATA : pos TYPE char3. "Position of Char in the Input String
*Input string
ipstr = '<FT><H><T> Line Clearance </></></>'.
*Removing only "</>"
REPLACE ALL OCCURRENCES OF '</>' IN ipstr WITH ' '.
*Removing only "<"
REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '.
CONDENSE ipstr.
*Length of Input String
len = STRLEN( ipstr ).
DO len TIMES.
*Char by Char
ch = ipstr+pos(1).
pos = pos + 1.
*Scan each char in input String for ">"
FIND '>' IN ch IGNORING CASE.
IF sy-subrc = 0.
num = len - pos.
*Output String
opstr = ipstr+pos(num).
ENDIF.
ENDDO.
WRITE :/ opstr.
This will help you to modify any type of strings .. in the code i have pasted it removes HTML tags .. instead of that just give the punctuation marks ..
Hope this answer helps you
Regards ..
Manthan
‎2010 Feb 23 9:16 AM
Hi ,
Please see my question " I have asked do i need to explictly give all the punctuations marks or is there is some other way round".
Anyways thanks for ur Advise and Help.
‎2010 Feb 23 9:24 AM
Hello,
Which version of SAP are you in ?
If you have Reg-ex available then you can make use of [:punct:]
E.g.,
REPLACE ALL OCCURENCES OF REGEX [:punct:] IN V_STRING WITH ` `.BR,
Suhas
Edited by: Suhas Saha on Feb 23, 2010 3:00 PM
‎2010 Feb 23 10:10 AM
Hi Paresh,
the correct format would be,
REPLACE ALL OCCURRENCES OF REGEX '[[:punct:]]' IN v_string WITH ''.Regards,
Herwin.
Edited by: Herwin Wilmet Dsouza on Feb 23, 2010 11:11 AM
‎2010 Feb 23 10:14 AM