将字符串按照某一字符拆开为CString类型的数组

int strInfoDecodeToIntList(char *buf, char compartChr, CString *list, int listCnt, int *cnt)
{
    char *p1 = NULL, *p2 = NULL, numInfoStr[128] = { 0 };
    int i = 0;
    unsigned int len = 0, srtSize = sizeof(numInfoStr);
    if (!buf || !list || listCnt <= 0 || !cnt) return -1;
    *cnt = 0;
    p1 = buf;
    p2 = p1;
    while (p2 && i < listCnt)
    {
        p2 = strchr(p2, compartChr);
        if (p2)
        {
            if ((len = p2 - p1)<srtSize)
            {
                   strncpy(numInfoStr, p1, len);
                list[i] = numInfoStr;
            }
            p2++;
            p1 = p2;
        }
        else
        {
            if (strlen(p1)<srtSize)
            {
                strcpy(numInfoStr, p1);
                list[i] = numInfoStr;
            }
        }
        i++;
    }
    *cnt = i;
    return 0;
}

char* buf: 你要进行拆分的字符串
char compartChr: 某一进行比较的字符
CString* list: 拆分后形成的数组
int listCnt: 你预估拆分后数组的大小
int* cnt: 实际上拆分后数组的大小

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值