字符串函数 [英] string function
问题描述
如何用
np(新字符串)替换其他字符串中的p(字符串)的出现..
char * replace _pattern (char * s,char * p,char * np)
请帮助我!!!!!
" dimitris67" < XI ****** @ hol.gr>写道:
#如何用
#np(新字符串)替换其他字符串中的p(字符串)的出现..
#char *替换_pattern(char * s,char * p,char * np)
#请帮助!!!!!
C库中没有任何内容。实现它的一种方法是建立一个新字符串。
使用ststr搜索p中的p。将字符从s复制到strstr找到的位置
匹配新字符串,将np复制到新字符串,然后在找到的子字符串之后前进
。继续使用strstr搜索其余的
s。当strstr找不到任何东西时,将剩下的,不匹配的s部分复制到
新字符串。
-
SM Ryan http://www.rawbw.com/~wyrmwif/
标题没有规定行为。
dimitris67写道:
如何替换p的出现(一个字符串)在其他字符串中使用
np(新字符串)..
char * replace _pattern(char * s,char * p,char * np)
请帮助我!!!!!
它非常简单,使用快速kmp(knuth-morris-pratt)算法进行搜索
所有出现的string1中的pattern1和下一个创建新字符串
pattern2(kmp将字符串中的偏移量返回到pat1,这样你就可以用pat2替换pat1
)。
-
----------------------------------- ----------
www.cepa.one.pl
FreeBSD r0xi qrde; - ]
使用strstr以便它给出第一次出现字符串s2在
字符串s1中,然后复制替换字符串。
,因为每个人都知道
while(* s2 ++ = * s1 ++);
做strcpy的操作
查看
>
How can I replace an occurence of p(a string) in an other string(s) with
np(new string)..
char* replace _pattern(char *s,char *p,char *np)
PLEASE HELP ME!!!!!
"dimitris67" <xi******@hol.gr> wrote:
# How can I replace an occurence of p(a string) in an other string(s) with
# np(new string)..
# char* replace _pattern(char *s,char *p,char *np)
# PLEASE HELP ME!!!!!
Nothing in the C library. One way to implement it is to build up a new string.
Use ststr to search for p in s. Copy characters from s to where strstr found
a match to the new string, copy np to the new string, and then advance p
past the found substring. Continue searching with strstr through the rest of
s. When strstr finds nothing, copy the remaining, unmatched portion of s to
the new string.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Title does not dictate behaviour.
dimitris67 wrote:
How can I replace an occurence of p(a string) in an other string(s) with
np(new string)..
char* replace _pattern(char *s,char *p,char *np)
PLEASE HELP ME!!!!!
its is quite easy, use fast kmp (knuth-morris-pratt) algorithm for searching
all occurrences of pattern1 in string and next create new string with
pattern2 (kmp returns offsets to pat1 in string so you can replace pat1
with pat2).
--
---------------------------------------------
www.cepa.one.pl
FreeBSD r0xi qrde ;-]
use strstr so that it gives the first occurence of the string s2 in
string s1 and then copy the replacing string .
as every body knows
while(*s2++=*s1++);
do the operation of strcpy
check it out
这篇关于字符串函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!