Shmewnix Shmewnix - 2 months ago 11
Vb.net Question

How to Trim consecutive Characters VB.net

I'm looking to trim (drop) consecutive characters, and everything in front of it in vb.net.

An example of the output:

*017834
^018730
%018411


What I'd like to do - is trim '01' and any character in front of it. So my desired output would be:

7834
8730
8411


I attempted to use

Dim charsToTrim() As Char = { "01"c}


However, you're only allowed to use 1 character at a time this way in vb.net. Since i may have "0" or "1", I can't break it up like this:

Dim charsToTrim() As Char = { "0"c,"1",c}

Answer
Function Trim01(ByVal input As String) As String
    Dim pos = input.IndexOf("01")

    Return If(pos >= 0, input.Substring(pos + "01".Length), input)
End Function
Comments