75 lines
3.9 KiB
VB.net
75 lines
3.9 KiB
VB.net
Imports System.Text.RegularExpressions
|
|
|
|
Public Class ClassPostprocessing
|
|
Public Shared Function Get_Nachbearbeitung_Wert(idxvalue As String, DTNB As DataTable) As String
|
|
Dim result As String = idxvalue
|
|
Try
|
|
For Each row As DataRow In DTNB.Rows
|
|
Select Case row.Item("TYPE").ToString.ToUpper
|
|
Case "VBSPLIT"
|
|
If LogErrorsOnly = False Then ClassLogger.Add(" ... Nachbearbeitung mit VBSPLIT", False)
|
|
Dim strSplit() As String
|
|
strSplit = result.Split(row.Item("TEXT1"))
|
|
For i As Integer = 0 To strSplit.Length - 1
|
|
If i = CInt(row.Item("TEXT2")) Then
|
|
If LogErrorsOnly = False Then ClassLogger.Add(" ... Split-Ergebnis für Index (" & i.ToString & "): " & strSplit(i), False)
|
|
result = strSplit(i).ToString
|
|
End If
|
|
Next
|
|
Case "VBREPLACE"
|
|
If LogErrorsOnly = False Then
|
|
ClassLogger.Add(" ... Nachbearbeitung mit VBREPLACE", False)
|
|
ClassLogger.Add(" ... Ersetze '" & row.Item("TEXT1") & "' mit '" & row.Item("TEXT2") & "'", False)
|
|
result = result.Replace(row.Item("TEXT1"), row.Item("TEXT2"))
|
|
End If
|
|
|
|
result = result.Replace(row.Item("TEXT1"), row.Item("TEXT2"))
|
|
Case "Regular Expression"
|
|
If LogErrorsOnly = False Then ClassLogger.Add(" ... NAchbearbeitung mit RegEx", False)
|
|
Dim RegexList As New List(Of System.Text.RegularExpressions.Regex)
|
|
Dim Regex As New System.Text.RegularExpressions.Regex(row.Item("TEXT1"), System.Text.RegularExpressions.RegexOptions.IgnoreCase)
|
|
RegexList.Add(Regex)
|
|
'
|
|
Dim resultRegex = ClassPostprocessing.extractFromStringviaRE(result, RegexList)
|
|
If Not IsNothing(resultRegex) Then
|
|
If LogErrorsOnly = False Then ClassLogger.Add(" ... Ergebnis des RegEx: " & resultRegex.ToString, False)
|
|
result = resultRegex.ToString
|
|
Else
|
|
ClassLogger.Add("Postprocessing RegEx konnte kein ergebnis auswerten!", True)
|
|
End If
|
|
End Select
|
|
Next
|
|
Return result
|
|
Catch ex As Exception
|
|
ClassLogger.Add(" - Unvorhergesehener Fehler bei Get_Nachbearbeitung_Wert - result: " & result & " - Fehler: " & vbNewLine & ex.Message)
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler bei Get_Nachbearbeitung_Wert:")
|
|
Return result
|
|
End Try
|
|
|
|
End Function
|
|
|
|
''' <summary>
|
|
''' Extrahiert aus dem String anhand einer Liste von Regular Expressions ein Ergebnis.
|
|
''' </summary>
|
|
''' <param name="SearchString">Der zu untersuchende String erzeugt wurden.</param>
|
|
''' <param name="RegexList">Eine Liste von Regular Expressions</param>
|
|
''' <param name="RegexGroup">Die Ergebnisgruppe, die die Adresse enthält</param>
|
|
''' <returns>Eine Emailadresse oder Nothing, wenn keine der Regular Expressions ein Ergebnis lieferte.</returns>
|
|
Public Shared Function extractFromStringviaRE(SearchString As String, RegexList As List(Of Regex), Optional RegexGroup As Integer = 1)
|
|
If IsNothing(SearchString) Then
|
|
Return Nothing
|
|
End If
|
|
|
|
For Each rx In RegexList
|
|
Dim match As Match = rx.Match(SearchString)
|
|
Dim result As String = match.Groups(RegexGroup).Value
|
|
If Not String.IsNullOrWhiteSpace(result) Then
|
|
'Nur den ersten Wert zurückgeben
|
|
Return result
|
|
End If
|
|
Next
|
|
|
|
Return Nothing
|
|
End Function
|
|
End Class
|