Solved

Help with checking string format? (Windows App VS 2010, with VB.NET)

Posted on 2012-12-27
2
222 Views
Last Modified: 2012-12-27
Hi,

I need to make sure my string s is in the following format: xxxx-xx-xxx-xxxx

How do check to make sure s is in the desired format, if not return an error message?

Or if length is 13 characters , s = 1305000200923, convert the string to 1305-00-020-0923

Thanks,

Victor
0
Comment
Question by:vcharles
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
How about?

If System.Text.RegularExpressions.Regex.IsMatch(theString, "^\d{13}$") 
    theString = theString.Insert(9, "-").Insert(6, "-").Insert(4, "-")
ElseIf Not System.Text.RegularExpressions.Regex.IsMatch(theString, "^\d{4}-\d{2}-\d{3}-\d{4}$") Then
    ' string does not match; return error
End If

Open in new window

0
 

Author Closing Comment

by:vcharles
Comment Utility
Thank You!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now