-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringUtil.bas
45 lines (39 loc) · 1.89 KB
/
StringUtil.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Attribute VB_Name = "StringUtil"
'--------------------------------------------------------------------
' String-Utils (Hilfsfunktionen für Strings)
'--------------------------------------------------------------------
'--------------------------------------------------------------------
' Prüfe ob ein String mit einem bestimmten anderen String endet
'--------------------------------------------------------------------
Public Function EndsWith(str As String, ending As String) As Boolean
Dim endingLen As Integer
endingLen = Len(ending)
EndsWith = (Right(Trim(UCase(str)), endingLen) = UCase(ending))
End Function
'--------------------------------------------------------------------
' Prüfe ob ein String mit einem bestimmten anderen String beginnt
'--------------------------------------------------------------------
Public Function StartsWith(str As String, start As String) As Boolean
Dim startLen As Integer
startLen = Len(start)
StartsWith = (Left(Trim(UCase(str)), startLen) = UCase(start))
End Function
'--------------------------------------------------------------------
' Finde das erste Zeichen aus einer Auswahl aus Zeichen in einem String
' und gibt dessen Index zurück
' z. B. StringUtil.FirstInStr("Was wäre, wenn...?", ".,?") => 9
' StringUtil.FirstInStr("Was wäre, wenn...?", ".?") => 15
' StringUtil.FirstInStr("Was wäre, wenn...?", "?") => 18
'--------------------------------------------------------------------
Public Function FirstInStr(str As String, chars As String) As Long
Dim index As Long
Dim c As Integer
FirstInStr = 0
For c = 1 To Len(chars)
index = InStr(str, Mid(chars, c, 1))
'Debug.Print Mid(chars, c, 1) & " @ " & index
If index <> 0 And (index < FirstInStr Or FirstInStr = 0) Then
FirstInStr = index
End If
Next
End Function