处理英文单词换行显示

     在smartforms实际使用中经常会遇到换行的情况,如果是中文,那还好办,如果是英文,就经常会出现英文单词分两行显示的情况,因此,我自己写了个处理function,能够纠正这种错误,如果要换行,之前会用空格补足位数。

FUNCTION zsplittext.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(FIXLENGTH) TYPE  I
*"  CHANGING
*"     REFERENCE(ORITEXT) TYPE  STRING
*"----------------------------------------------------------------------

*"AS,DFG HJKL,ASDFJ,SDKF22
*"----------------------------------------------------------------------

  DATA: tmp_text TYPE string,
        char,
        tmp_text1 TYPE string,
        tmp_sub_t TYPE string,
        sub_t TYPE string.
  DATA: textlength TYPE i,
        f_length TYPE i,
*        comm_n TYPE i,
        t_length1 TYPE i,"累加字符串长度
        t_length2 TYPE i,
        t_length3 TYPE i,
        t_rown TYPE i,"
        space_length TYPE i,
        sub_text_len TYPE i.
  DATA: dt_subt1 TYPE TABLE OF string,
        dt_subt2 TYPE TABLE OF string.
  TYPES: BEGIN OF s_subt,
        sub_text TYPE string,
        splitsign(5) TYPE c,
        END OF s_subt.
  DATA: dt_subtext TYPE TABLE OF s_subt WITH HEADER LINE.
  DATA: l_tabix LIKE sy-tabix.

  textlength = STRLEN( oritext ).
  IF textlength > fixlength.
*    comm_n = fixlength - 1.
*    tmp_text = oritext+comm_n(3).
    char = oritext+fixlength(1).
    IF char <> ' ' AND char <> ',' AND char <> '.'.
      SPLIT oritext AT ',' INTO TABLE dt_subt1."先用,分割
*      IF sy-subrc <> 0.
*        APPEND oritext TO dt_subt1.
*      ENDIF.
      LOOP AT dt_subt1 INTO sub_t.
        l_tabix = sy-tabix.
        tmp_sub_t = sub_t.
        CONDENSE tmp_sub_t NO-GAPS.
        IF STRLEN( tmp_sub_t ) < STRLEN( sub_t ).
          SPLIT sub_t AT space INTO TABLE dt_subt2."再用空格分割

          LOOP AT dt_subt2 INTO sub_t.
            dt_subtext-sub_text = sub_t.
            IF sy-tabix = 1.
              dt_subtext-splitsign = ','.
            ELSE.
              dt_subtext-splitsign = 'space'.
            ENDIF.
            APPEND dt_subtext.
          ENDLOOP.
        ELSE.
          dt_subtext-sub_text = sub_t.
          IF l_tabix <> 1.
            dt_subtext-splitsign = ','.
          ENDIF.
          APPEND dt_subtext.
        ENDIF.
      ENDLOOP.

      CLEAR tmp_text.
      LOOP AT dt_subtext.
        t_length1 = STRLEN( tmp_text ).
        t_length3 = t_length1 - t_rown * fixlength.
        sub_text_len = STRLEN( dt_subtext-sub_text ).
        IF t_length1 = 0.
          tmp_text = dt_subtext-sub_text.
        ELSE.
          IF t_length3 < fixlength.
            IF dt_subtext-splitsign = ','.
              CONCATENATE tmp_text dt_subtext-sub_text INTO tmp_text SEPARATED BY ','.
            ELSEIF dt_subtext-splitsign = 'space'.
              CONCATENATE tmp_text dt_subtext-sub_text INTO tmp_text SEPARATED BY space.
            ENDIF.
          ENDIF.

          t_length1 = STRLEN( tmp_text ).
          t_length3 = t_length1 - t_rown * fixlength.

          IF t_length3 = fixlength.
            IF dt_subtext-splitsign = ','.
              CONCATENATE tmp_text ',' INTO tmp_text.
              sub_text_len = sub_text_len + 1.
            ELSEIF dt_subtext-splitsign = 'space'.
              CONCATENATE tmp_text dt_subtext-sub_text INTO tmp_text SEPARATED BY space.
            ENDIF.
          ENDIF.

          t_length1 = STRLEN( tmp_text ).
          t_length3 = t_length1 - t_rown * fixlength.

          IF t_length3 > fixlength.
            t_rown = t_rown + 1.
            f_length = t_rown * fixlength - 1.
            tmp_text1 = tmp_text+f_length(1).

            IF tmp_text1 <> ' ' AND tmp_text1 <> ','.
*             计算需要几个空格来填充一行到末尾
              t_length2 = t_length1 - sub_text_len.
              space_length = fixlength - ( t_length3 - sub_text_len ).
*             先把最后加上的字符串去掉
              tmp_text = tmp_text+0(t_length2).
*             循环加空格
              DO space_length TIMES.
                CONCATENATE tmp_text '' INTO tmp_text SEPARATED BY space.
              ENDDO.
              CONCATENATE tmp_text dt_subtext-sub_text INTO tmp_text.
            ELSE.
              CONCATENATE tmp_text dt_subtext-sub_text INTO tmp_text SEPARATED BY space.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
      oritext = tmp_text.
    ENDIF.
  ENDIF.
ENDFUNCTION.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值