I have a list with texts with lengths ranging from 1 character to several thousands. I want to cut off all texts exceeding 255 characters. How can I do that? Do I have to check the length of each String and then cut it with (255) or is there a more elegant expression?
Edit: like this
<% IF STRLEN( wa_comm-text ) > 255. %>
<%= wa_comm-text(255) %> ...
<% ELSE. %>开发者_JAVA技巧;
<%= wa_comm-text %>
<% ENDIF. %>
this is BSP
Thanks in advance
The other option is:
<%
data: ls_text(255) type c.
ls_text = wa_comm-text.
%>
<%= ls_text %>
Because you obviously cannot use substrings on strings, and if they are shorter, you will get a runtime error.
I created for this a 'string solutions' class called zss, with a static method that will cut off a given string and the given length.
Then you can just do something like this:
<%= zss=>left( s = wa_comm-text cutoff = 255 ). %>
or even a more specific method
<%= zss=>left255( wa_comm-text ). %>
Just as an option:
<%= CONV char255( wa_comm-text ) %>
inline conversion and trimming to target type is done here.
精彩评论