Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Originally Richard helped me with the first portion of my problem which was parsing the richtextbox data.

here is the code:

Dim rows() As String = Regex.Split(RichTextBox1.Text, "^\r?$", RegexOptions.Multiline)
       Dim pattern As New Regex("^\s*(?<label>[^:]+)\s*:\s*(?<value>.+)\s*\r?$", RegexOptions.Multiline)

       For Each row As String In rows
           Dim lastName As String = Nothing, firstName As String = Nothing, race As String = Nothing, sex As String = Nothing
           Dim matches As MatchCollection = pattern.Matches(row)
           For Each match As Match In matches
               Dim label As String = match.Groups("label").Value
               If String.Equals(label, "last Name", StringComparison.OrdinalIgnoreCase) Then
                   lastName = match.Groups("value").Value

               ElseIf String.Equals(label, "First Name", StringComparison.OrdinalIgnoreCase) Then
                   firstName = match.Groups("value").Value


               ElseIf String.Equals(label, "Race", StringComparison.OrdinalIgnoreCase) Then
                   race = match.Groups("value").Value

               ElseIf String.Equals(label, "Sex", StringComparison.OrdinalIgnoreCase) Then

               End If

           Next


I have been trying to work on the 2nd portion of my problem. Now to make the process skip over a value if it is not present.

so let's say I have -

First Name: jeff
last Name: jones
Race: B

First Name: steve
last Name: need

First Name: lance
Sex: M
Race: W

you can see in these examples have other fields that others do not. I want to skip over the information that is not present, possibly even put a blank string "" in just to move the process along.

What I have tried:

I have tried the value =
Match.Empty.Value
I have tried to use the skip command, but I just keep getting a null reference error.
Posted
Updated 21-Jan-17 15:37pm
v2
Comments
Member 11856456 20-Jan-17 3:48am    
I still haven't figured it out, but I am reading about match.success, I am trying to figure out how to implement it into the current code that if a specific section does not match then skip over that.
Richard Deeming 20-Jan-17 8:40am    
If one of the labels doesn't exist, the variable will be Nothing. If you want to use an empty string instead, just replace the four = Nothing initialization statements with = String.Empty.
Member 11856456 20-Jan-17 14:01pm    
I tried using an else statement.

If String.Equals(label, "last Name", StringComparison.OrdinalIgnoreCase) Then
lastName = match.Groups("value").Value
else
lastName = string.empty

the error is still saying it needs a parameter @lastname.
Member 11856456 20-Jan-17 16:44pm    
I also have tried this method:

ElseIf String.IsNullOrEmpty("last Name") Then
lastName = Nothing

still getting the parameter error

1 solution

I have figured it out I had to use an if statement within the sql add command parameter.
 
Share this answer
 

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