VB.Net - String parsing

holemania
holemania used Ask the Experts™
on
Hello experts,

I created a small windows application in Visual Studio 2005 using VB.Net.  I would like to do some validation from a description textbox against a string(Field) i pull from a database.  I'm able to pull field from the database, but my issue is parsing it and comparing it with what's in the textbox that is also parsed.

Example data from database:

FT " RoundBar

Example data from Textbox.

10FT 4" RoundBar

Parse and compare textbox partial match text against database field. If no match in the order as it come from the database, then prompt error on which column it doesn't have a match.

Textbox     =   DatabaseField
10FT       =   FT
4"            =  "
Roundbar = Roundbar

I guess the above would be a "Like" comparsion.  In that 10FT from textbox "FT" matches "FT" from the database field.  Not sure if this make sense, but I'm looking at validating that the text in the text box follow the format from the database field.  Desn't matter what numbers/letters is before the Text that needs to match.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dim goals = From goal  In WC  Where comment.DataVersionId.Contains("-" & Your TextBox info & "-") _
                               Select goal
                dgvComments.DataSource = comments.ToList // Using Linq you can use this command to get what you are looking for.
Shaun KlineLead Software Engineer

Commented:
Is the database field something that you are using elsewhere in your application? If not, you may want to consider using regular expressions to validate. I.e. change your database field to something like "([1-9]*[0-9]|[1-9])FT [1-9]" Roundbar".
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Author

Commented:
Sorry I had been out on vacation for a week and a half.  I will take a look and update.  I'm thinking more in terms of waht Shaun Kline suggest with using expression.  I had to build the SQL table as a lookup and might just use a field for expression.  

Here's an example:

From the application that I will validate, I have a textbox that they can type in the description as followed:

2.00"x4.50" LG .065 WL 14MPHT TRI 304

Is there a expression builder tool I can use to build the correct expression for this or would I have to  create each expression manually?  I have over 150 validation, and depending on what prefix is selected from the drop down, it has a different expression to compare to.
Lead Software Engineer
Commented:
You can go to http://www.regular-expressions.info/ for reference information for creating regular expressions, and it has links to regular expression tools. I've not used any of them, but you may find them helpful.

Author

Commented:
Is there any way to have it flag me where there's no match using regular expression?  I was able to get a tool that will let me build the expression.  Very nice utility and thanks for the suggestion.  Would be nice to tell user where the error is.
Dim FoundMatch As Boolean = False
Try
	Dim RegexObj As New Regex("^\d+\.\d{2}""x\d+\.\d{2}"" LG \d*\.\d{3} WL [0-9]+MPHT TRI [0-9]+$", RegexOptions.Singleline)
        FoundMatch = RegexObj.IsMatch(txtDescription.Text)
Catch ex As Exception
        MsgBox(ex.Message)
End Try

Open in new window

Shaun KlineLead Software Engineer

Commented:
It appears that the Match/IsMatch functions are all or nothing, meaning that if the regular expression matches and grouping was used (the use of parentheses), you can get the value of the matched group. If the regular expression does not match, you cannot determine if any of the groups matched.

Author

Commented:
Thanks that's what I was afraid it is doing.  I can't find any resource any where.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial