Solved

Get String split

Posted on 2016-11-20
5
66 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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