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

How to remove all whitespaces from a string?

Former Member
0 Likes
5,705

I'm trying to conduct hash check on payment file to see if anyone has changed the payment file manually before signing it with a digital signature.

However when I download the payment file from the server some whitespaces go missing on the way to the client's computer. The problem is that a file that hasn't been modified in any way produces a different hash after signing. So I was thinking what if i removed all whitespaces (space, linefeed, carriage return, nbsp) from the file then maybe it finally calculates correct hash for both files. However I can't find any functionality that lets me remove all whitespace characters from the string. Alpha Conversion removes spaces from the end of the string but since I need to also remove spaces and line breaks from inside the string this isn't really an option. I would greatly appreciate if someone provided me with some information how to achieve this.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,533

These are all good suggestions but afterall I went with something I made myself especially because I can be sure that this way all the unnecessary characters are removed and necessary characters remain:

len = strlen( initial_file ).

DO len TIMES.

     SUBTRACT 1 FROM len.

     IF 'ABCDEFGHIJKLMNOPQRSÅ ZŽTUVÕÄÖÜXY1234567890.,"<>?=-:/' CS initial_file+len(1).

          CONCATENATE initial_file+len(1) temp into temp.

     ENDIF.

ENDDO.

5 REPLIES 5
Read only

Former Member
0 Likes
3,533

Hi,

data: teststring type string .

replace all occurrences of cl_abap_char_utilities=>CR_LF in teststring with '' .

replace all occurrences of cl_abap_char_utilities=>NEWLINE in teststring with '' .

condense teststring.

For more options you can explore class CL_ABAP_CHAR_UTILITIES

regards,

Ashish Rawat

Read only

paul_max1
Explorer
0 Likes
3,533

Hello Rauno,

Try with REPLACE ALL OCCURRENCES OF pattern IN variable WITH ''.

I hope that I understood well your question.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,533

Hello Rauno,

since I need to also remove spaces and line breaks from inside the string this isn't really an option.

I think you can use the RegEx [[:space:]] to remove the "white-space characters" from your string.

BR,

Suhas

PS - You can play around with your RegEx in DEMO_REGEX_TOY & build the one which suits your requirement

Read only

Former Member
0 Likes
3,533

Hi ,

   Please try like this,

REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>newline in
   variable_name WITH ''.

Thanks,

Vijay.

Read only

Former Member
0 Likes
3,534

These are all good suggestions but afterall I went with something I made myself especially because I can be sure that this way all the unnecessary characters are removed and necessary characters remain:

len = strlen( initial_file ).

DO len TIMES.

     SUBTRACT 1 FROM len.

     IF 'ABCDEFGHIJKLMNOPQRSÅ ZŽTUVÕÄÖÜXY1234567890.,"<>?=-:/' CS initial_file+len(1).

          CONCATENATE initial_file+len(1) temp into temp.

     ENDIF.

ENDDO.