?
Solved

Get String split

Posted on 2016-11-20
5
Medium Priority
?
76 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 29

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 29

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 29

Accepted Solution

by:
Pawan Kumar earned 2000 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 29

Expert Comment

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

Regards,
Pawan
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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