I have a string like this:
std::string string1 = \"xjdfhfakdjs%54k34k.-jk34\";
I need to get only \"\"xjdfhfakdjs\", but the string is dyna
I believe that will work.
std::string mystr = string1.substr(0, string1.find("%", 0));
Did a C-like thing which does work in its current form, but certainly more clunky than the methods shown above:
#include <windows.h>
void main ()
{
int i;
wchar_t searchString[100];
wchar_t * stringReturn;
memset(searchString, L'\0', sizeof(stringReturn));
wcscpy_s(searchString, 100, L"String\\ to search");
stringReturn = wcschr (searchString, '\\');
if (stringReturn)
{
for (i = 0; i < (int)(stringReturn - searchString); i++) stringReturn[i] = searchString[i];
stringReturn[i] = L'\0';
wcscpy_s(searchString, 100, stringReturn);
}
}
Can be easily modified to work for dynamic strings.
std::string the_prefix_you_want = string1.substr(0, string1.find("%"));
See: http://www.cplusplus.com/reference/string/string/find/ and http://www.cplusplus.com/reference/string/string/substr/ for more details