Problem solve Get help with specific problems with your technologies, process and projects.

Replace text in RPG IV easier than %Replace BIF

Replacing text in a string.

When I need to replace text in a string, in example subst the accents to prepare an HTML string, I want an easy method like c Eval j_Return=@ReplaceDes(j_Return:'a':'à')

This function is likely that the %Replace BIF but more easy of use. With only 2 parameters, the result text is wrapped.


 		PROCEDURE DECLARATIONS
d  @ReplaceDes    PR          9999a               
d    p_Text                   9999a   Value       
d    p_Aquest                  128a   Value       
d    p_XAquest                 128a   Value       

PROCEDURE SPECIFICATIONS
p*---------------------------------------------------        
p  @ReplaceDes    B                                          
d  @ReplaceDes    PI          9999a                          
d    p_Text                   9999a   Value                  
d    p_Aquest                  128a   Value                  
d    p_XAquest                 128a   Value                  
d*                                                           
d                                                            
d  j_Return       s           9999a                          
d  xIn            s              6  0                        
d  j_LongA        s              6  0                        
d  j_LongX        s              6  0                        
c*                                                           
c*                                                                       
c                   Eval      j_Return = p_Text                          
c*                                                                       
c* Localitzem on esta Aquest                                             
c                   Eval      j_LongA = %Len(%Trim(p_Aquest))            
c                   Eval      j_LongX = %Len(%Trim(p_Text))              
c                   Dou       1 = 0                                      
c                   Eval      xIn = %Scan(%Trim(p_Aquest):j_Return)      
c*                                                                       
c                   Select                                               
c*                                                                       
c* Si no hi ha cap, sortim de la rutina                                  
c                   When      xIn = 0                                    
c                   Return    j_Return                                   
c                   Leave                                                
c*                                                                       
c* Si es el primer caracter, ho fem de manera especial                   
c                   When      xIn = 1                                    
c                   Eval      j_Return  =                                
c                             %Trim(i_Buffer) +                          
c                              %Subst(p_Text:2:j_LongX)                
c                   Eval      p_Text = j_Return                        
c*                                                                     
c* Coloquem a DataWarp la part anterior a &&                           
c                   When      xIn > 1                                  
c                   Eval      j_Return  = %Subst(p_Text:1:xIn-1) +     
c                             %Trim(i_Buffer) +                        
c                              %Subst(p_Text:xIn+j_LongA:j_LongX-xIn+  
c                                                        j_LongA)      
c                   Eval      p_Text = j_Return                        
c*                                                                     
c                   EndSl                                              
c*                                                                     
c* Mirem si hi ha algun altra cosa per substituir                      
c                   EndDo                                              
c*                                                                     
c*                                                                     
p                 E         

Dig Deeper on RPG iSeries programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close