Hi all,
I need help in trimming everything in my string till end after it encounters the first "\0"
So:
"test\1\2\3\0\0\0\0\0\0\0\0\0_asdfgh_qwerty_blah_blah_blah"
becomes
"test\1\2\3"
I am using c#. Help would be greatly appreciated.
Thanks.
Hi all,
I need help in trimming everything in my string till end after it encounters the first "\0"
So:
"test\1\2\3\0\0\0\0\0\0\0\0\0_asdfgh_qwerty_blah_blah_blah"
becomes
"test\1\2\3"
I am using c#. Help would be greatly appreciated.
Thanks.
How about:
string s = "test\1\2\3\0\0\0\0\0\0\0\0\0_asdfgh_qwerty_blah_blah_blah";
int offset = s.IndexOf("\\0");
if (offset >= 0)
s = s.Substring(0, offset);
if (someString.Contains("\\0"))
someString = someString.Substring(0, someString.IndexOf("\\0"));
Find the position of the first occurrence of "\0" and make another string which is a substring of you original from start to the position of the first occurrence.
if (origString.IndexOf(@"\0") != -1) {
newString = origString.Substring(0, origString.IndexOf(@"\0");
} else {
newString = origString;
}
The match value returned by the following regex should be what you're after as well (as alternative to the substring method), basically it begins at the string start and as long as the next two characters aren't \0
it expands the match:
^(?:(?!=\0).)+