Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1066809
  • 博文数量: 106
  • 博客积分: 9093
  • 博客等级: 中将
  • 技术积分: 2770
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 17:22
文章分类

全部博文(106)

文章存档

2014年(1)

2012年(29)

2011年(32)

2010年(20)

2008年(24)

分类: 系统运维

2012-05-28 15:20:28

虽然你已经在程序中写过字符串了,你还没学过它们的用处。首先我们解释一下字符串是什么东西。

字符串通常是指你想要展示给别人的、或者是你想要从程序里导出的一小段字符。RPGLE通过文本里的单引号 ' 识别出字符串来。这在你以前的DSPLY 练习中你已经见过很多次了。如果你把单引号括起来的文本放到 DSPLY 前面或后面,它们就会被打印出来。

       RPGLE中有xlate%xlate)、subst%subst)、scan%scan)和check(%check)等操作字符串的操作符或function 下面是他们的一些简单的用法,其他用法可以到IBM I信息中心了解
EX5
0001.00 D Lo              C                   'abcdefghijklmnopqrstuvwxyz'      
0002.00 D Up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'      
0003.00 D*                                                                      
0004.00 D String_text     C                   'This is a test string using -    
0005.00 D                                     function xlate'                   
0006.00 D*                                                                      
0007.00 D Digits          C                   '0123456789'                      
0008.00 D*                                                                      
0009.00 D Salary          S             10    inz('$2000.')                     
0010.00 D Result          S             50    inz(*blanks)                      
0011.00 D T               S              2  0 inz(29)                           
0012.00 D Wait            S              1A                                     
0013.00 D pos             S              5U 0 inz(*zero)                        
0014.00 C     String_text   Dsply                                               
0015.00 c*                                                                      
0016.00 C     Lo:Up         xlate     String_text   Result                      
0017.00 C     Result        Dsply                                               
0018.00 c*                                                                      
0019.00 c     8             subst(p)  String_text:T Result                      
0020.00 c     Result        dsply                                               
0021.00 c*                                                                      
0022.00 c     'xlate'       scan      String_text   pos                      90 
0023.00 c                   eval      Result = %char(pos)                       
0024.00 c     Result        dsply                                               
0025.00 c*                                                                      
0026.00 c     Digits        check     Salary:2      pos                         
0027.00 c                   eval      Result = %char(pos)                       
0028.00 c     Result        dsply                   Wait                        
0029.00 C*                                                                      
0030.00 C                   Eval      *inlr = *on                               
0031.00 C                   Return              

EX5f
0001.00 D Lo              C                   'abcdefghijklmnopqrstuvwxyz' 
0002.00 D Up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
0003.00 D*                                                                 
0004.00 D String_text     C                   'This is a test string using -
0005.00 D                                     function xlate'              
0006.00 D*                                                                 
0007.00 D Digits          C                   '0123456789'                 
0008.00 D*                                                                 
0009.00 D Salary          S             10    inz('$2000.')                
0010.00 D Result          S             50    inz(*blanks)                 
0011.00 D T               S              2  0 inz(29)                      
0012.00 D Wait            S              1A                                
0013.00 D pos             S              5U 0 inz(*zero)                   
0014.00  /free                                                             
0015.00    Dsply String_text;                                              
0016.00                                                                    
0017.00    Result = %xlate(Lo:Up:String_text);                             
0018.00    Dsply Result;                                                   
0019.00                                                                    
0020.00    Result = %subst(String_text:T:8);                               
0021.00    Dsply Result;                                                   
0022.00                                                                    
0023.00    pos = %scan('xlate':String_text);                               
0024.00    Result = %char(pos);                                            
0025.00    Dsply Result;                                                   
0026.00                                                                    
0027.00    pos = %check(Digits:Salary:2);                                  
0028.00    Result = %char(pos);                                            
0029.00    Dsply Result '' Wait;                                           
0030.00                                                                    
0031.00    *inlr = *on;                                                    
0032.00    return;                                                         
0033.00                                                                    
0034.00  /end-free  

你应该看到的内容


加分练习

1.      在每一行的上面写一行注解,给自己解释一下这一行的作用

2.      SUBST后面的(p)是做什么用的,去掉他会怎么样,为什么free格式不用

3.      当使用SUBST时,想截取的长度 > 被截取string的长度 开始位置 + 1,会发生什么,怎么处理

4.      SUBST后面的90是做什么用的,为什么free格式不用

5.      研究一下scancheck的其他用法



阅读(1106) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~