I have a question regarding replacing some characters with regex or any other best practice or efficient way.
Here is what I have as input, it has mostly the same form: A/ABC/N/ABC/123
The output should look like this: A_ABC_NABC123, basically the first 2 / should be changed to _ and the rest removed.
Of course i could do with some String.Replace. etc one by one, but I don’t think it is a good way to do that. I search for a better solution.
So how to do it with Regex?
This will do it, although there may be a simpler way:
I’ve wrapped the code like this to make sure you don’t accidentally the
intvariable.Edit: There’s also this overload which stops after a certain number of replacements, but you’d have to do it in two steps: replace the first two
/with_, then replace the remaining/with nothing.