Ternyata lumayan lama ya saya tidak posting disini, tuntutan kerja yang sangat menyebalkan sehingga saya tidak punya banyak waktu, namun di kesempatan kali ini saya akan mencoba memberikan beberapa fungsi String.
Menghilangkan karakter-karakter tertentu pada awal String
Menghilangkan karakter-karakter tertentu pada akhir String
Menghilangkan karakter-karakter tertentu pada awal dan akhir String
Memeriksa kandungan teks tertentu pada seluruh bagianString
Memeriksa kandungan teks tertentu pada awal String
Memeriksa kandungan teks tertentu pada akhir String
Selamat Mencoba.
Menghilangkan karakter-karakter tertentu pada awal String
Function TrimStart(Source As Variant, ParamArray sChar()) As String
Dim i As Integer
Dim j As Integer
Dim strNewChar As String
Dim strResult As String
Source = Trim(CStr(Source))
If Len(Source) = 0 Then Exit Function
strResult = ""
For i = 1 To Len(CStr(Source))
strNewChar = Mid(Source, i, 1)
For j = LBound(sChar) To UBound(sChar)
If strNewChar = sChar(j) Then
strNewChar = ""
End If
Next
strResult = strResult & strNewChar
If strNewChar "" Then
Dim intLast As Integer
intLast = i + 1
strResult = strResult & Mid(Source, i + 1)
Exit For
End If
Next
Source = strResult
TrimStart = Source
End Function
Menghilangkan karakter-karakter tertentu pada akhir String
Function TrimEnd(Source As Variant, ParamArray sChar()) As String
Dim i As Integer
Dim j As Integer
Dim strNewChar As String
Dim strResult As String
Source = Trim(CStr(Source))
Source = StrReverse(CStr(Source))
If Len(Source) = 0 Then Exit Function
strResult = ""
For i = 1 To Len(CStr(Source))
strNewChar = Mid(Source, i, 1)
For j = LBound(sChar) To UBound(sChar)
If strNewChar = sChar(j) Then
strNewChar = ""
End If
Next
strResult = strResult & strNewChar
If strNewChar "" Then
Dim intLast As Integer
intLast = i + 1
strResult = strResult & Mid(Source, i + 1)
Exit For
End If
Next
Source = StrReverse(strResult)
TrimEnd = Source
End Function
Menghilangkan karakter-karakter tertentu pada awal dan akhir String
Function TrimAll(Source As Variant, ParamArray sChar()) As String
Dim i As Integer
Dim j As Integer
Dim strNewChar As String
Dim strResult As String
Dim intLast As Integer
Source = Trim(CStr(Source))
If Len(Source) = 0 Then Exit Function
strResult = ""
For i = 1 To Len(CStr(Source))
strNewChar = Mid(Source, i, 1)
For j = LBound(sChar) To UBound(sChar)
If strNewChar = sChar(j) Then
strNewChar = ""
End If
Next
strResult = strResult & strNewChar
If strNewChar "" Then
intLast = i + 1
strResult = strResult & Mid(Source, i + 1)
Exit For
End If
Next
Source = strResult
Source = Trim(CStr(Source))
Source = StrReverse(CStr(Source))
If Len(Source) = 0 Then Exit Function
strResult = ""
For i = 1 To Len(CStr(Source))
strNewChar = Mid(Source, i, 1)
For j = LBound(sChar) To UBound(sChar)
If strNewChar = sChar(j) Then
strNewChar = ""
End If
Next
strResult = strResult & strNewChar
If strNewChar "" Then
intLast = i + 1
strResult = strResult & Mid(Source, i + 1)
Exit For
End If
Next
Source = StrReverse(strResult)
TrimAll = Source
End Function
Memeriksa kandungan teks tertentu pada seluruh bagianString
Function Contains(Source As String, FindText As String) As Boolean
If InStr(1, Source, FindText, vbTextCompare) 0 Then
Contains = True
End If
End Function
Memeriksa kandungan teks tertentu pada awal String
Function StartWith(Source As String, FindText As String) As Boolean
If LCase(Mid(Source, 1, Len(FindText))) = LCase(FindText) Then
StartWith = True
End If
End Function
Memeriksa kandungan teks tertentu pada akhir String
Function EndsWith(Source As String, FindText As String) As Boolean
If LCase(Right(Source, Len(FindText))) = LCase(FindText) Then
EndsWith = True
End If
End Function
Selamat Mencoba.
Terima kasih sudah menyempatkan waktu untuk membaca artikel Fungsi-Fungsi String Ala VB.Net Di VB6. Jika terdapat link error silahkan langsung hubungi saya di menu Contact supaya bisa langsung di perbaiki dan jangan lupa tinggalkan komentar kamu setelah selesai membaca artikel ini. Salam Admin
Ditulis oleh:
Unknown - Friday, 27 December 2013