相关疑难解决方法(0)

用另一个子串C++替换substring

我怎么能用C++中的另一个子字符串替换字符串中的子字符串,我可以使用哪些函数?

eg: string test = "abc def abc def";
test.replace("abc", "hij").replace("def", "klm"); //replace occurrence of abc and def with other substring
Run Code Online (Sandbox Code Playgroud)

c++ string replace substring

79
推荐指数
8
解决办法
14万
查看次数

替换出现的NSString - iPhone

我有一个很长的NSString,我试图替换特殊字符.我的部分字符串如下所示:

"veau (c\u00f4telette)","veau (filet)","agneau (gigot)","agneau (c\u00f4telette)","b**\u0153**uf (hach\u00e9)","porc (hach\u00e9)"
Run Code Online (Sandbox Code Playgroud)

我想用"oe"替换所有\ u0153.我试过了:

[response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];
Run Code Online (Sandbox Code Playgroud)

但它不起作用....我不明白为什么!

iphone replace objective-c nsstring

34
推荐指数
2
解决办法
5万
查看次数

如何替换c中的子串?

这个例子有效,但我认为内存泄漏.如果使用此功能,则在简单Web服务器模块中使用的函数会因共享内存而增加.

    char *str_replace ( const char *string, const char *substr, const char *replacement ){
      char *tok = NULL;
      char *newstr = NULL;
      char *oldstr = NULL;
      if ( substr == NULL || replacement == NULL ) return strdup (string);
      newstr = strdup (string);
      while ( (tok = strstr ( newstr, substr ))){
        oldstr = newstr;
        newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) + 1 );
        memset(newstr,0,strlen ( oldstr ) …
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
6780
查看次数

标签 统计

replace ×2

c ×1

c++ ×1

iphone ×1

nsstring ×1

objective-c ×1

string ×1

substring ×1