Solved

Get String split

Posted on 2016-11-20
5
54 Views
Last Modified: 2016-11-24
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
0
Comment
Question by:Sam OZ
  • 4
5 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41895309
could you please provide some patterns of wrongdocument name?
0
 

Author Comment

by:Sam OZ
ID: 41895342
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)
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41895351
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 !!
0
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 500 total points
ID: 41895354
I think this will be even better..

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 = ""       
      
       Output = str.Substring(str.LastIndexOf("_") + 1)       

    End Sub

Open in new window

1
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41897032
Hi Sam,
Is this done?

Regards,
Pawan
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question