VB.Net Remove Everything After Third Hyphen
regex, vb.net
Solution
A rapid solution
string test = "170-0175-00B-BEARING PLATE MACHINING.asm:2";
int num = 2;
int index = test.IndexOf('-');
while(index > 0 && num > 0)
{
index = test.IndexOf('-', index+1);
num--;
}
if(index > 0)
test = test.Substring(0, index);
of course, if you are searching for the last hyphen then is more simple to do
int index = test.LastIndexOf('-');
if(index > 0)
test = test.Substring(0, index);
Problem
Here is the string I am looking to modify: 170-0175-00B-BEARING PLATE MACHINING.asm:2 I want to keep "170-0175-00B". So I need to remove the third hyphen and whatever is after it.