开发者

How to only copy the exact index element from a string array?

I am working on this code, a开发者_开发百科nd got confused.. How to only get the 10th element and above only to be copied into the buffer?

For example, I have this string "http://www.google.com". I don't want the "http://www." part to be copied inside my testDest buffer.

  char testDest[256];
  char *p= _com_util::ConvertBSTRToString(URL->bstrVal);

  for (int i = 0; i <= strlen(p); i++)    
  {
    testDest[i] = p[i];   
  }


You shouldn't do this by counting. What if the next address is https://www. or if the link doesn't even have a www in it? For things like this, your best friend is "Pattern Matching".

But if you really know what you're doing, just let your for-loop begin at 10 instead of zero:

for (int i = 9; i <= strlen(p); i++)
{
    testDest[i-9] = p[i];
}

Also, this isn't really C++ what you're doing. C++ has much nicer alternatives than using char buffers. Just saying :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜