Link to home
Start Free TrialLog in
Avatar of Sam OZ
Sam OZFlag for Australia

asked on

Get String split

Hi experts,
    I need to get  a  
The documentNumber is a string type variable . The typical value has actual number and the revision at the end after _ (Underscore)
  A-BB-C-DD_1
   A-BB-C-DD_10

 Also it has to consider the possibility of a wrongly named  document
    WrongPattern_StillNeedtoPick_1

    From the above 3 examples , I need to get the result as follows  ( ActualName , Rev are variables of string type)

      ActualName                                               Rev
       A-BB-C-DD                                                 1
      A-BB-C-DD                                                  10
     WrongPattern_StillNeedtoPick                 1

      I have some idea to do this with  split function . Still looking for comprehend code
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

could you please provide some patterns of wrongdocument name?
Avatar of Sam OZ

ASKER

Hi Pawan,
     Wrong pattern can have _ anywhere  potentially . But  the the text after  final _  should be taken as the Rev and rest should be taken as Document name ( as in examples of my original post)
Please try..

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim str As String = "A-BB-C-DD_10"
        Dim Output As String = ""       

        If str.IndexOf("A-BB-C-DD_") <> -1 Then
            Output = str.Substring(str.IndexOf("A-BB-C-DD_") + "A-BB-C-DD_".Length)
        Else
            Output = str.Substring(str.LastIndexOf("_") + 1)
        End If

    End Sub

Open in new window


Hope it helps !!
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Sam,
Is this done?

Regards,
Pawan