Index: trunk/psLib/src/sys/psString.c
===================================================================
--- trunk/psLib/src/sys/psString.c	(revision 6278)
+++ trunk/psLib/src/sys/psString.c	(revision 6874)
@@ -13,6 +13,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-01 20:40:56 $
+ *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-17 22:00:03 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -214,2 +214,43 @@
 }
 
+// given the input string, search for all copies of the key, and replace with the replacement value
+// the input string may be freed if not needed
+char *psStringSubstitute (char *input, char *replace, char *key)
+{
+
+    char *p;
+
+    if (key == NULL)
+        return input;
+    if (strlen(key) == 0)
+        return input;
+
+    while (true) {
+        p = strstr (input, key);
+        if (p == NULL)
+            return input;
+
+        // we have input = xxxkeyxxx
+        // we want output = xxxreplacexxx
+
+        // this is safe since we will subtract strlen(key) elements from input
+        char *output = psAlloc(strlen(input) + strlen(replace) + 1);
+        int Nc = p - input;
+
+        // copy the first segement into 'output'
+        strncpy (output, input, Nc);
+
+        // copy the key replacement to the start of the key
+
+        strcpy (&output[Nc], replace);
+        Nc += strlen (replace);
+
+        // copy the remainder to the end of the replacement
+        strcpy (&output[Nc], p + strlen(key));
+
+        psFree (input);
+        input = output;
+    }
+    return input;
+}
+
