Link Search Menu Expand Document

CSVDocument.Replace Method

Explanation Replace data in cells of specified column at once.
By stating the condition, selected cell can be replaced.

Added since Ver.4.1.0 Mobile Ver.3.0.0
Call format var ret = csvdoc.Replace( row, col, val [, cond1 [, cond2, … ] ] )
Return value Number of updated cell.
Arguments integer row Column number starting with 0 on the column that starts the replacement.
The rows after the row specified by row will be replaced.
integer col Column number starts with 0 on the column that starts the replacement.
String val Character string to bet set.
The string can be specified directly, or can specify the value in another column in the following format.
    "[列番号]"
    

Example:-
    "[3]"
    

In this example,the cell that matches the condition is replaced with the values in the 4th column of the same row.

If the replacement string starts with "[", escape it with "\ [". Note that \ is an escape character in the CRS language, so if specify it as a string constant in a CRS script, \ must be specified twice.
Example:-
    "\\[12\\]"
    
String cond Search criteria for cells to replace
Format is specified same as Load method.
Can specify as many search conditions as desired,as long as the maximum same as the number of columns, and if specify more than one, combine them with AND.
Exception CSV-14 Incorrect column index
Example of use
    var csvdoc = new CSVDocument;
    csvdoc.Get("http://server/data1.csv");
    
    /* Updated the first column of every row to "new data" */
    csvdoc.Replace(0, 0, "new data");
    
    /* Update the second column of all rows to the same value as the third column */
    csvdoc.Replace(0, 1, "[2]");
    
    /* Updated the 5th column of the row where the 4th column is "1" to the same value as the 3rd column */
    csvdoc.Replace(0, 4, "[2]", "3==1");
    
    /* 6th column is the same row as 7th column, 8th column is updated to the same value as 3rd column */
    csvdoc.Replace(0, 7, "[2]", "5==[6]");
    
Related item Load, Find methods