有效地将一个字符串插入另一个字符串 [英] Insert a string into another string efficiently

查看:26
本文介绍了有效地将一个字符串插入另一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

char aa[] = { "你好,!"};

char bb[] = { "世界" };

如何用cstring最高效地将bb插入aa中?

How to insert bb into aa the most efficiently with cstring ?

推荐答案

  • 分配足够大的缓冲区(malloc/new[])
  • 将 aa 字符串的第一部分复制到缓冲区中 (strncpy/memcpy)
  • 复制bb字符串(strcpy/memcpy)
  • 复制 aa 字符串的其余部分 (strncpy/memcpy)
    • allocate big enough buffer (malloc/new[])
    • copy the first part of the aa string into the buffer (strncpy/memcpy)
    • copy the bb string (strcpy/memcpy)
    • copy the rest of the aa string (strncpy/memcpy)
    • 这篇关于有效地将一个字符串插入另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆