Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Find and replace text data in a table
 
  chubbard posted this script:
  This function searches for a substring in a text field in a table, and replaces all instances of that substring with the specified string. The function takes the name of the table, the name of the RowId column in that table (optional), the name of the column to search, the string to search for, and the string with which to replace it.

webcall function SingleFieldReplace(strTableName, strRowIdName, strColName, strFind, strReplace)
{
    if(strRowIdName == "")
        strRowIdName = "RowId";

    var aCols = new Array(strRowIdName, strColName);
    var rs = new Resultset(strTableName, aCols, strColName + " LIKE '%" + strFind + "%'");

    while(rs.next())
        {
        //get record text.
        var strText = rs[strColName];
      
        //find and replace all instances of search string.
        strText = substringReplace(strText, strFind, strReplace);

        //update record.
        var fld = new Object();
        fld[strColName] = strText;
        Table.update(strTableName, fld, rs[strRowIdName]);
        }
}

public function substringReplace(theString, searchString, replaceString)
{
    return theString.split(searchString).join(replaceString);
}
 
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us