C++ win32下 分割文本 防易语言的思路 返回的也是数组指针
stringsplit(char *haystack, char *needle, string value[]){
char *buf_t = strstr(haystack, needle);
string Shy;
if (buf_t != NULL)
{
string Shaystack = haystack;
string Sneedle = needle;
string Sn2 = Shaystack.substr(Shaystack.length() - Sneedle.length(), Sneedle.length());
if (Sn2 != Sneedle)
{
Shaystack = Shaystack + Sneedle;
Shy = Shaystack;
}
else
{
Shy = haystack;
}
}
else
{
return "";
}
char *hay = (char*)Shy.c_str();
char aa = { 0 };
int index = 0;
char* buf = strstr(hay, needle);
while (buf != NULL)
{
int n = strlen(hay) - strlen(buf);
memcpy(aa, hay, n);
hay = hay + n;
value = aa;
index = index + 1;
ZeroMemory(aa, 1024);
hay = buf + strlen(needle);
buf = strstr(hay, needle);
}
return "";
}
页:
[1]