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

Does anybody have a sample trim function?

Former Member
0 Likes
1,477

Hi,

I would like to see a trim function that trims trailing spaces from both sides of the string (not whithin).

Thanks,

AG

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,002

You can use the SHIFT. In this example, the trailing spaces are simply not there when using a STRING field.



data: str type string.
data: len type i.
str = '       THIS IS A STRING         '.

len = strlen( str ).

write:/ str, len.
shift str left deleting leading space.

len = strlen( str ).

write:/ str, len.

Regards,

RIch Heilman

6 REPLIES 6
Read only

former_member187255
Active Contributor
0 Likes
1,002

use ..

<b>CONDENSE STRING.</b>

Message was edited by:

Ch@ndra

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,003

You can use the SHIFT. In this example, the trailing spaces are simply not there when using a STRING field.



data: str type string.
data: len type i.
str = '       THIS IS A STRING         '.

len = strlen( str ).

write:/ str, len.
shift str left deleting leading space.

len = strlen( str ).

write:/ str, len.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
1,002

Hi,

Please use CONDENSE statement.


CONDENSE WA_STRING.

Regards,

Ferry Lianto

Thanks, Rich!

Message was edited by:

Ferry Lianto

Read only

0 Likes
1,002

Of course, CONDENSE would work here too, but don't use NO-GAPS as this will get rid of any spaces within the value.



data: str type string.
data: len type i.
str = '       THIS IS A STRING         '.

len = strlen( str ).

write:/ str, len.
condense str.
*shift str left deleting leading space.

len = strlen( str ).

write:/ str, len.

Regards,

Rich HEilman

Read only

Former Member
0 Likes
1,002

Hi AG,

There is not function module avialable for TRIM function but your requirement can be achieved with SHIFT statement.

Check this code.

DATA V_STRING TYPE STRING VALUE

' empty string a b c d e f ghijkl'.

<b>SHIFT V_STRING LEFT DELETING LEADING SPACE.</b>

WRITE:/ V_STRING.

<b>CONDENSE</b> will supress spaces(if you had more than one or so) in between words in a string and will a single space between words.

Thanks,

Vinay

Read only

Former Member
0 Likes
1,002

condense string resolves this issue for me