int StrReplace( char pstrSrc[], char pstrDst[], char pstrOld[], char pstrNew[]);
0: 正常
-1: pstrOld[]の文字列長が0
-2: 置き換え後の文字数がpstrDst[]よりも大きい
pstrSrc[]: 対象となる文字列
pstrDst[]: 置き換え後の文字列を格納する配列
pstrOld[]: 置き換え対象の文字列
pstrNew[]: 置き換える文字列
pstrOldの文字列をpstrNewに置き換えます。
pstrSrcで与えられた文字列中にある、
pstrOldの文字列をpstrNewに置き換えます。
置き換えた後の文字列はpstrDstに格納されます。置き換えた後の文字列がpstrDstの配列長よりも大きい場合は関数は失敗し、-2を返却します。
RTX64-4.4 以降対応
〇PCベースコントローラ
×InterMotion
void main()
{
char csrc[32];
char cdst[32];
char cOld[16];
char cNew[32];
int r;
//test1
r = 0;
Sprintf1(csrc, "%s" , "Prime Motion Prime Motion\n");
Sprintf1(cOld, "%s" , "Prime");
Sprintf1(cNew, "%s" , "Motion");
r = StrReplace(csrc,cdst,cOld,cNew);
Printf1("r=%d\n", r);
Printf0(cdst); //"Motion Motion Motion Motion\n"
//test2
r = 0;
Sprintf1(csrc, "%s" , "Prime Motion Prime Motion\n");
Sprintf1(cOld, "%s" , "Motion");
Sprintf1(cNew, "%s" , "Prime");
r = StrReplace(csrc,cdst,cOld,cNew);
Printf1("r=%d\n", r);
Printf0(cdst); //"Prime Prime Prime Prime\n"
//test3
r = 0;
Sprintf1(csrc, "%s" , "Prime Motion Prime Motion\n");
Sprintf1(cOld, "%s" , "");
Sprintf1(cNew, "%s" , "Prime Prime Prime ");
r = StrReplace(csrc,cdst,cOld,cNew);
Printf1("r=%d\n", r); //-1 fromがempty
Printf0(cdst);
//test4
r = 0;
Sprintf1(csrc, "%s" , "Prime Motion Prime Motion\n");
Sprintf1(cOld, "%s" , "Motion");
Sprintf1(cNew, "%s" , "Prime Prime Prime ");
r = StrReplace(csrc,cdst,cOld,cNew);
Printf1("r=%d\n", r); //-2 出力バッファのオーバーフロー
Printf0(cdst);
}