标记化WCHAR字符串 [英] Tokenizing WCHAR string

查看:132
本文介绍了标记化WCHAR字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何识别以下代码中返回的字符串

How to tekenize the string returned in the below code

wchar_t m_VStrBuf[2048];

m_vNumChar=GetPrivateProfileString(_T("List1"),NULL,NULL,m_VStrBuf,2048,m_VFileName);



缓冲区(m_VFileName)中填充了一个或多个以NULL终止的字符串;



The buffer(m_VFileName) is filled with one or more null-terminated strings; the last string is followed by a second null character.

推荐答案

wchar_t *ts;

ts = m_VFileName;
while (wcslen(ts) != 0)
{
  //process string ts
  ts += wcslen(ts) + sizeof(wchar_t);  // skip to next string in result buffer
}



已键入但未运行/调试(但应关闭)



Typed but not run / debugged (but it should be close)
[edit - skip over the null too]


您可以使用strtok().像这样
You can use strtok(). like this
char * pch;

pch = strtok (m_VStrBuf,","); // Here , is seprator.
while (pch != NULL)
{
  pch = strtok (NULL, ",");
}


注意:要从文件u中获取值,必须使用分隔符存储该值.


Note : To fetch value from file u have to stored the value with seprator.


假设您要保留字符串,可以使用此(经过测试的)函数.
Assuming you want to keep the strings, you can use this (tested) function.
void tokenise_wstr(const wchar_t * str, size_t len, 
               std::vector<std::wstring>& strings)
{
  size_t prev = 0;
  size_t next = wcslen(str);

  while ( (prev < next ) && (next < len))
  {
    strings.push_back(
      std::wstring(str + prev, str + next + 1));
    prev = next + 1;
    next = prev + wcslen(str + prev);
  }
}


这篇关于标记化WCHAR字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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