J
John paul coder
Guest
Hello All,
I am tokenizing the string (" /test1:1111 /test2:2222 /test3:3333 /test4:4444") with name and its value (for eg., "/test1:1111").
Then getting the value(for eg., "1111") of the each string and storing it into the registry.
At the later point of time there might be a chance of adding many strings to the path. Is there any way can I add a generic function to find the value of the string and to store that value into the registry?
Below is the sample code snippet:
int main()
{
std::wstring str1(L"test1");
std::wstring str2(L"test2");
std::wstring fullPathStr;
fullPathStr = L" /test1:1111 /test2:2222 /test3:3333 /test4:4444";
wchar_t* ptrWStr;
wchar_t* buffer;
ptrWStr = wcstok_s((wchar_t*)fullPathStr.c_str(), L" ", &buffer);
while (ptrWStr != NULL)
{
std::wstring teststr = ptrWStr;
size_t pos = 0;
if ((pos = teststr.find(L"test1")) != std::wstring::npos)
{
teststr = teststr.substr(pos + str1.length() + 1);
// Will write the value into the registry
}
if ((pos = teststr.find(L"test2")) != std::wstring::npos)
{
teststr = teststr.substr(pos + str2.length() + 1);
// Will write the value into the registry
}
ptrWStr = wcstok_s(nullptr, L" ", &buffer);
}
return 0;
}
Continue reading...
I am tokenizing the string (" /test1:1111 /test2:2222 /test3:3333 /test4:4444") with name and its value (for eg., "/test1:1111").
Then getting the value(for eg., "1111") of the each string and storing it into the registry.
At the later point of time there might be a chance of adding many strings to the path. Is there any way can I add a generic function to find the value of the string and to store that value into the registry?
Below is the sample code snippet:
int main()
{
std::wstring str1(L"test1");
std::wstring str2(L"test2");
std::wstring fullPathStr;
fullPathStr = L" /test1:1111 /test2:2222 /test3:3333 /test4:4444";
wchar_t* ptrWStr;
wchar_t* buffer;
ptrWStr = wcstok_s((wchar_t*)fullPathStr.c_str(), L" ", &buffer);
while (ptrWStr != NULL)
{
std::wstring teststr = ptrWStr;
size_t pos = 0;
if ((pos = teststr.find(L"test1")) != std::wstring::npos)
{
teststr = teststr.substr(pos + str1.length() + 1);
// Will write the value into the registry
}
if ((pos = teststr.find(L"test2")) != std::wstring::npos)
{
teststr = teststr.substr(pos + str2.length() + 1);
// Will write the value into the registry
}
ptrWStr = wcstok_s(nullptr, L" ", &buffer);
}
return 0;
}
Continue reading...