Replace

From CometWiki

(Difference between revisions)
Jump to: navigation, search
(minor)
Line 2: Line 2:
  Length dynamic & local section$ output$
  Length dynamic & local section$ output$
-
+
 
-
Top: Map _
+
  Top: Map _
-
  '**Title**',    Title$;_
+
Title$,    '**Title**';_
-
  '**Name**',    Name$;_
+
    Name$,      '**Name**';_
-
  '**Date**',    Date$;_
+
    Date$,      '**Date**';_
-
  '**Prog**',    Prog$;_
+
    Prog$,      '**Prog**';_
-
  '**Partition**',Partition$;_
+
    Partition$, '**Partition**';_
-
  '**Email**',    Eml$;_
+
    Eml$,      '**Email**';_
-
  '**Time**',    time$;_
+
    time$,      '**Time**';_
-
  '**timeout**',  timeout
+
    timeout,    '**timeout**'
-
+
 
  cust: Map _
  cust: Map _
-
   '**cusnum**,    cusnum$;_
+
    cusnum$,   '**cusnum**;_   
-
   '**custname**,  custname$
+
    custname$, '**custname**  
 +
 
    
    
  output$ = replace(top,section$)
  output$ = replace(top,section$)
Line 22: Line 23:
  Print output$
  Print output$
-
Will replace all of those names found in the map named "top" with their corresponding values, and then replace the customer info as well before sending the text to the browser. In the REPLACE function, names are case insensitive. If a given name is not found, nothing will change. The above example uses asterisks ("**") to make the names unique and to imitate the legacy xap merge control, but any string can be used as the name.
+
Will replace all of those names found in the map named "top" with their corresponding values, and then replace the customer info as well before sending the text to the browser or anywhere else you desire. In the REPLACE function, names are case insensitive. If a given name is not found, nothing will change. The above example uses asterisks ("**") to make the names unique and to imitate the legacy xap merge control, but any string can be used as the name.
The replace function is general purpose and can be used in any program to manipulate string data. As a bonus, here is a small Comet32 proc that will replace multiple instances of one substring with another in a target string.  
The replace function is general purpose and can be used in any program to manipulate string data. As a bonus, here is a small Comet32 proc that will replace multiple instances of one substring with another in a target string.  
Line 29: Line 30:
     ! Replaces All Instances Of From$ With To$ In The Target String.
     ! Replaces All Instances Of From$ With To$ In The Target String.
  String Replacex(From$, To$, Target$)
  String Replacex(From$, To$, Target$)
-
     Map: Map From$,To$
+
     Map: Map To$, From$
     Procreturn Replace(Map,Target$)
     Procreturn Replace(Map,Target$)
  End
  End

Revision as of 16:21, 19 May 2011

The Replace function is used to replace names in a string with corresponding values, using a MAP to designate name/value pairs.

Length dynamic & local section$ output$
 Top: Map _

Title$, '**Title**';_

   Name$,      '**Name**';_
   Date$,      '**Date**';_
   Prog$,      '**Prog**';_
   Partition$, '**Partition**';_
   Eml$,       '**Email**';_
   time$,      '**Time**';_
   timeout,    '**timeout**'
cust: Map _
   cusnum$,   '**cusnum**;_   
   custname$, '**custname** 


output$ = replace(top,section$)
output$ = replace(cust,output$)

Print output$

Will replace all of those names found in the map named "top" with their corresponding values, and then replace the customer info as well before sending the text to the browser or anywhere else you desire. In the REPLACE function, names are case insensitive. If a given name is not found, nothing will change. The above example uses asterisks ("**") to make the names unique and to imitate the legacy xap merge control, but any string can be used as the name.

The replace function is general purpose and can be used in any program to manipulate string data. As a bonus, here is a small Comet32 proc that will replace multiple instances of one substring with another in a target string.


   ! Replaces All Instances Of From$ With To$ In The Target String.
String Replacex(From$, To$, Target$)
   Map: Map To$, From$
   Procreturn Replace(Map,Target$)
End

Once this Proc is included in your program, all you have to do to call it is this:

a$ = replacex('his','my',b$)
Personal tools