Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7203286
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2008-03-18 16:20:28

*&---------------------------------------------------------------------*
*& Report  Z_BARRY_TEST                                                *
*&                                                                     *
*&---------------------------------------------------------------------*
*& 程序1:非UNICODE使用,提取汉字/英文字母等                                *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  z_barry_nounicode NO STANDARD PAGE HEADING .
DATA: input1(100) TYPE c ,
      outch1(100) TYPE c ,
      outen1(100) TYPE c ,
      len TYPE i.
 
input1 = 'a中bcde三萨格发'.
PERFORM unicode USING input1 outch1 outen1 len.
 
WRITE :  / 'Input:       ' , input1 ,
         / '提取双字节:  ' , outch1 ,
         / '提取单字节:  ' , outen1 ,
         / 'UNICODE长度: ' , len .
*&---------------------------------------------------------------------*
*&      Form  nounicode
*&---------------------------------------------------------------------*
FORM unicode USING value(input) TYPE c
                     outch TYPE c
                     outen TYPE c
                     unicodelen TYPE i.
  DATA: inlen TYPE i,
        charlen TYPE i,
        n TYPE i ,
        m TYPE i .
  inlen = STRLEN( input ).
  DO .
    charlen = CHARLEN( input ) .
    IF charlen = 2 .
      CONCATENATE outch input+0(2) INTO outch.
    ELSE.
      CONCATENATE outen input+0(1) INTO outen.
    ENDIF.
    unicodelen = unicodelen + 1 .
    SHIFT input BY charlen PLACES LEFT IN CHARACTER MODE .
    inlen = STRLEN( input ).
    IF inlen <= 0 . EXIT. ENDIF.
  ENDDO.
ENDFORM.  
 
 
 
 
 
*&---------------------------------------------------------------------*
*& 程序2:UNICODE系统使用                                               *
*&---------------------------------------------------------------------*
REPORT  z_barry_test.
DATA: input1(100) TYPE c ,
      outch1(100) TYPE c ,
      outen1(100) TYPE c ,
      len TYPE i.
 
input1 = '中国zhongguo人民renmin'.
PERFORM nounicode USING input1 outch1 outen1 len.
WRITE :  / 'Input:        '  , input1 ,
         / '提取双字节:   ' , outch1 ,
         / '提取单字节:   ' , outen1 ,
         / 'ANSI长度  :' , len .
 
*&---------------------------------------------------------------------*
*&      Form  nounicode
*&---------------------------------------------------------------------*
FORM nounicode USING input TYPE c
                     outch TYPE c
                     outen TYPE c
                     ansilen TYPE i.
  DATA: inlen TYPE i,
        n TYPE i ,
        result_tab TYPE match_result_tab .
 
  ansilen = cl_abap_list_utilities=>dynamic_output_length( input ) .
  FIND ALL OCCURRENCES OF REGEX '[[:unicode:]]' IN input RESULTS result_tab.
  inlen = STRLEN( input ) .
  DO inlen TIMES.
    n = sy-index - 1.
    READ TABLE result_tab TRANSPORTING NO FIELDS WITH KEY offset = n BINARY SEARCH.
    IF sy-subrc = 0.
      CONCATENATE outch input+n(1) INTO outch.
    ELSE.
      CONCATENATE outen input+n(1) INTO outen.
    ENDIF.
  ENDDO.
ENDFORM.                    "nounicode
阅读(4699) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-12-01 17:38:44

有意思

chinaunix网友2010-11-23 15:18:43

受教了...