C
C#•2y 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
ero•2y 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 GeezerOP•2y ago
thanks 🙂 Was thinking if it could be done in a one liner. But that works too so can't complain
ero
ero•2y 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
Want results from more Discord servers?
Add your server