如果不存在,则跳过richtextbox值 [英] Skip over richtextbox value if it does not exist

查看:64
本文介绍了如果不存在,则跳过richtextbox值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初Richard帮我解决了问题的第一部分,即解析richtextbox数据。



这里是代码:



 Dim rows()As String = Regex.Split(RichTextBox1.Text,^ \r?$,RegexOptions.Multiline)
Dim pattern As New正则表达式(^ \ * *(?< label> [^:] +)\ * *:\ * *(?< 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匹配As MatchCollection = pattern.Matches(row)
For Each Match As Match In匹配
Dim label As String = match.Groups(label)。Value
If String.Equals( label,last Name,StringComparison.OrdinalIgnoreCase)然后
lastName = match.Groups(value)。Value

ElseIf String.Equals(lab el,First Name,StringComparison.OrdinalIgnoreCase)然后
firstName = match.Groups(value)。Value


ElseIf String.Equals(label,Race ,StringComparison.OrdinalIgnoreCase)然后
race = match.Groups(value)。Value

ElseIf String.Equals(label,Sex,StringComparison.OrdinalIgnoreCase)然后

结束如果

下一个





我一直在努力问题的第二部分。现在让进程跳过一个值,如果它不存在。



所以让我说我有 -



名字:jeff

姓氏:jones

种族:B



名字:史蒂夫

姓氏:需要



名字:lance

性别:M

种族:W



你可以在这些例子中看到其他领域没有的其他领域。我想跳过不存在的信息,甚至可能只是用一个空白的字符串来移动过程。



我有什么尝试过:



我试过了值=

 Match.Empty.Value 

我试过使用skip命令,但我只是一直得到一个空引用错误。

解决方案

,RegexOptions.Multiline)
Dim pattern As New Regex(^ \s *(小于标签> [^:] +)\s *:\s *(小于值GT; +?)\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匹配As MatchCollection = pattern.Matches(row)
For Each Match As Match In匹配
Dim label As String = match.Groups(label)。Value
如果是String.Equ als(label,last Name,StringComparison.OrdinalIgnoreCase)然后
lastName = match.Groups(value)。Value

ElseIf String.Equals(label,First Name, StringComparison.OrdinalIgnoreCase)然后
firstName = match.Groups(value)。值


ElseIf String.Equals(label,Race,StringComparison.OrdinalIgnoreCase)然后
race = match.Groups(value)。Value

ElseIf String.Equals(label,Sex,StringComparison.OrdinalIgnoreCase)然后

结束如果

下一个





我一直在努力解决问题的第二部分。现在让进程跳过一个值,如果它不存在。



所以让我说我有 -



名字:jeff

姓氏:jones

种族:B



名字:史蒂夫

姓氏:需要



名字:lance

性别:M

种族:W



你可以在这些例子中看到其他领域没有的其他领域。我想跳过不存在的信息,甚至可能只是用一个空白的字符串来移动过程。



我有什么尝试过:



我试过了值=

 Match.Empty.Value 

我试过使用skip命令,但我只是一直得到一个空引用错误。


我已经弄清楚了我必须在sql add命令参数中使用if语句。


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.

解决方案

", 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.


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


这篇关于如果不存在,则跳过richtextbox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆