Click here to Skip to main content
15,889,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like my function to follow some convention to check if my ticket number needs formatting or not.
If the convention is not met, then I would like to make some changes to the ticket number.
Example
Ticket number 19K3072216 needs to be formatted to this 19-K3-07-002216 because it does not meet the following conditions.
For this ticket number, I would like to do the following:
1. Check if the 1st 2 digits has a value 0 - 9 (numeric)
2. Check if the 3rd digit has a value of A or Z
3. Check if the 4th digit has a value 0 - 9 (numeric)
4. Check if the 5th and 6th digits has a date value (e.g.2 digit year - 17, 90, 15 etc)
5. Check if the next 6 digits i.e. 7th - 12th digits are numeric
Because ticket number 19K3072216 does not meet the above conditions, I would like my function to format it to look like this 19-K3-07-002216
So Return strCaseNumber should contain formatted ticket number 19-K3-07-002216
My vb.net function
VB
Public Class Ticket_Code

    Public Shared Sub main()
        Dim strTicketNumber As String = FixTicketNumber("19K3072216")

    End Sub
    
    Public Shared Function FixCaseNumber(ByVal astrCaseNumber As String) As String
        Dim strCaseNumber As String = Replace(astrCaseNumber, "-", "")

        'Determine if ticket number is formatted
         How do I do this?


        'If ticket number is formatted add 2 zeros
         'How do I do this?

        'Else return unchanged
         'If ticket number is already formatted, just returned the number (original number)

        Return strCaseNumber

    End Function


End Class

What I have tried:

<pre lang="vb">Public Shared Function FixCaseNumber(ByVal astrCaseNumber As String) As String
        Dim strCaseNumber As String = Replace(astrCaseNumber, "-", "")

        'Determine if case is a converted TCIS case number



        'If TCIS converted case number add zero if necessary


        'Else return unchanged

        Return strCaseNumber

    End Function
Posted
Updated 6-Feb-17 11:55am
v2
Comments
[no name] 6-Feb-17 15:37pm    
You would use a combination of the string class methods to check the various parts of the string and use the integer class method TryParse to check the parts of the string that you need to check for integer values. I am sure that this was covered by your teacher in class.

1 solution

I would use RegEx , first to check if value match expectations, formatted or not, then I would do a replace to force formatting.
I would start with a RegExlike like (\d\d)-?([A-Z]\d)-? .
-----
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
Comments
Member 11403304 7-Feb-17 8:32am    
ppolymorphe thanks for helping I did use RegXe and now my code is working!. Thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900