2.2.4.9.30 DataRange::Replace

Description

Threshold or matching string replacement for a DataRange.

Syntax

BOOL Replace( double dThresholdVal, double dReplaceVal, uint wBitwiseOptions = WKSREPL_TEST_EQUAL, int nIndex = 0, double rTolerance = 1e-8, BOOL bUndo = FALSE )


BOOL Replace( LPCSTR strOld, LPCSTR strNew, uint wBitwiseOptions = WKSREPL_TEST_STR_MATCH_WHOLE_WORD, int nIndex = 0, BOOL bUndo = FALSE )

Parameters

dThresholdVal
[input]Compared with original data
dReplaceVal
[input]Used to replace original data
wBitwiseOptions
[input]Replace options:
nIndex
[input]Range index
dAbsError
[input]Tolerance for Equal testing
bUndo
[input]Undo controller


strOld
[input]Compare with original string
strNew
[input]Used to replace original string
wBitwiseOptions
[input]Replace options:
WKSREPL_TEST_LESSTHAN = 1
WKSREPL_TEST_EQUAL = 2
WKSREPL_TEST_GREATER = 4
WKSREPL_USE_ABSOLUTE_VALUE_IN_TEST = 8
WKSREPL_KEEP_ORIGINAL_SIGN_WHEN_TEST_RESULT_IS_TRUE = 16
WKSREPL_SET_TO_MISSING_VALUE_WHEN_TEST_RESULT_IS_FALSE = 32
WKSREPL_TEST_STR_MATCH_WHOLE_WORD = 64
WKSREPL_TEST_STR_WILDCARD_MATCHING = 128
WKSREPL_TEST_STR_CASE_SENSITIVE = 256
nIndex
[input]Range index
bUndo
[input]Undo controller

Return

Returns TRUE if successful else return FALSE


Returns TRUE if successful else return FALSE

Examples

EX1

//Replace the data<=50 in the worksheet with 50.
void DataRange_Replace_Ex1(int nCol1 = 0, int nCol2 = 1)
{
    //Creat a worksheet with two columns and fill with data.
    Worksheet wks ;
    wks.Create();
    if( wks )
    {
        while(wks.Columns(0))
            wks.DeleteCol(0);

        wks.AddCol("A");
        wks.AddCol("B");
        double rr;
        for(int j=0;j<2;j++)
        {
            for (int i=0;i<10;i++)
            {
                   rr=rnd();
                   wks.SetCell(i,j,rr*100);
            }
        }
        
        //Create a datarange with X and Y subranges.   
        DataRange dr;
        dr.Add("X", wks, 0, nCol1, -1, nCol1);
        dr.Add("Y", wks, 0, nCol2, -1, nCol2);

        int nNumRanges = dr.GetNumRanges();
        uint wBitwiseOptions = WKSREPL_TEST_LESSTHAN | WKSREPL_TEST_EQUAL;
        for(int ii = 0; ii < nNumRanges; ii++)
            dr.Replace(50, 50, wBitwiseOptions, ii);//replace the data value <= 50 with 50.
    }
}



EX2

//Add ".cn" in the end of each sample string.
void DataRange_Replace_Ex2(int nCol1 = 0)
{
    //Create a worksheet and fill with strings.
    Worksheet wks;
    wks.Create();
    if(wks)
    {
    	//Create sample data.
        wks.SetCell(0, 0, "angel@originlab.com");
        wks.SetCell(1, 0, "amy@originlab.com");
        wks.SetCell(2, 0, "betty@originlab.com");
        wks.SetCell(3, 0, "carol@originlab.com");
 
        //Create a datarange with two subranges.
        DataRange dr;
        dr.Add("Range1", wks, 0, nCol1, -1, nCol1);
 
        //Match the whole string.
        uint nOptions = WKSREPL_TEST_STR_MATCH_WHOLE_WORD;   
        Column col(wks, 0);
        int nNumRows = col.GetNumRows();
        string strText;
        for(int ii = 0; ii < nNumRows; ii++)
        {
        	 wks.GetCell(ii, 0, strText);
             dr.Replace(strText, strText+".cn", nOptions, 0); //Add ".cn" in the end of the string.
        }
    }
}

Remark

See Also

vectorbase::Replace

Header to Include

origin.h