如何从WCHAR数组中获取子字符串 [英] how to get substring from WCHAR array

查看:321
本文介绍了如何从WCHAR数组中获取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WCHAR 的数组是这样的



WCHAR Path [ 256]; 所以我在我的函数getpath(Path)中传递了这个数组,它正在填充路径中的值,如下所示:// device / systemName /



所以我想从上面的字符串中只获得设备



我的代码在这里

I have one array of WCHAR is like this

WCHAR Path[256]; so I'm passing this array in my function getpath(Path) and It's filling the value in path like this: //device/systemName/

So I want to get only device from above string

My code is here

WCHAR *pDevName;

int i = 0;
int j = 0;   
while(Path[i] != NULL){ 
    if(0 ==(wcscmp(Path, L"/")))
    {
        
        //i = i + 2;
        ++i;
        continue;
    }
    
    else
    {
        pDevName[j] = Path[i];
        
        ++i;
        ++j;
        if (0 == wcscmp(Path, L"/")){
            break;
        }
    }



我的代码正在编译,但它不是从WCHAR数组返回给我的设备。它正在撤退// devicename / systemName /。它来自pDevName。



我对wcscmp()的比较有疑问。所以我的问题是如何比较/与剩余的wchar数组值。



P.S. :devicename可以是c:或xyz。



请帮助这对我来说非常紧急。

推荐答案

查看 <$ c的文档$ c> wcscmp() [ ^ ];您的代码永远不会工作,因为您正在将完整路径与单个字符进行比较。你最好使用 wcschr() [ ^ ]查找分隔符字符,或 wcstok_s() [ ^ ]将您的路径分成其组成部分。
Look at the documentation for wcscmp()[^]; your code will never work because you are comparing a full path with a single character. You would be better using something like wcschr()[^] to find the separator characters, or wcstok_s()[^] to split your path into its constituent parts.


这篇关于如何从WCHAR数组中获取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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