C
C#16mo ago
Diesel Geezer

How can i remove a substring from index i to first index of a or b character

Here is how i think it would work. How can i do that?
3 Replies
ero
ero16mo ago
int start = i;
int end = strAfterSlash.IndexOf('\\');
if (end == -1) // not found
{
end = strAfterSlash.IndexOf(' ');
}

Str = Str.Remove(start, end);
int start = i;
int end = strAfterSlash.IndexOf('\\');
if (end == -1) // not found
{
end = strAfterSlash.IndexOf(' ');
}

Str = Str.Remove(start, end);
Diesel Geezer
Diesel Geezer16mo ago
thanks 🙂 Was thinking if it could be done in a one liner. But that works too so can't complain
ero
ero16mo ago
It can, but don't
Str = Str.Remove(i, (i = strAfterSlash.IndexOf('\\')) != -1 ? i : strAfterSlash.IndexOf(' '));
Str = Str.Remove(i, (i = strAfterSlash.IndexOf('\\')) != -1 ? i : strAfterSlash.IndexOf(' '));
Just omega ugly