C言語関数で記述されたコードでReplaceAll

コンテンツ開発プロセスのいくつかは、多くの場合、コレクション、C言語で記述されたコンテンツでReplaceAll機能に関する次の情報に使用されます。

書式#include <stdio.hに>
する#include <malloc.hを>
する#include <string.hの>

{(== NULL || replaceWith == NULL見つける。)であれば
、戻りのstrdup(SRC)を
}
int型のカウント= 0;
int型I、J、K。

int型srcLen = strlen関数(SRC);
int型findLen = strlen関数(見つけます);
INT replaceWithLen = STRLEN(replaceWith)。

int型cpStrStart = 0;

カウント= getFindStrCount(SRC、見つけます。);
(== 0をカウント){場合
、戻りはstrdup(SRC);
}

のmemset(afterReplaceHead、 '0'はsizeof(afterReplaceHead))。

(; srcLen I =; I = 0、J = 0、K = 0!私は++)のために{
IF(SRC [I] ==見つける[J]){
IF(J == 0){
k = I。
}
(jは==(findLen-1)){もし
J = 0。
strncpyを(afterReplaceIndex、srcIndex、I - findLen - cpStrStart + 1)。
afterReplaceIndex = afterReplaceIndex + I - findLen - cpStrStart + 1。
srcIndex = srcIndex + I - findLen - cpStrStart + 1。
cpStrStart = I 1を+。

strncpyを(afterReplaceIndex、replaceWith、replaceWithLen)。
afterReplaceIndex = afterReplaceIndex + replaceWithLen。
srcIndex = srcIndex + findLen。
}他{
J ++。
}
}他{
IF(!J = 0){
I = K。
}
J = 0。
}
}
はstrncpy(afterReplaceIndex、srcIndex、I - cpStrStart)。

afterReplaceHeadを返します。
}

int型のカウント= 0;
int型findLen = strlen関数(見つけます);
(!(位置=はstrstr(位置、見つける。))= NULL){しばらく
++数えます。
位置=位置+ findLen。
}
カウントを返します。
}

INTメイン(ボイド){
のprintf( "%のSN"、R)。
フリー(R)
0を返します。
}







おすすめ

転載: www.cnblogs.com/s-squirrel/p/11242614.html