Fungsi-Fungsi String di VB.NET - Didalam
visual Basic ada banyak sekali fungsi-fungsi string, program sederhana yang
saya buat ini hanya menampilakan sebahagian fungsi string yang ada di visual
Basic.Net. bagi anda yang programmer pemula sangat cocok untuk mengetahui
fungsi-fungsi string yang sedehana dan mudah diingat J
Button/Teks
|
Name
|
LCase
|
Button1
|
UCase
|
Button2
|
Left
|
Button3
|
Right
|
Button4
|
Mid
|
Button5
|
LTrim
|
Button6
|
RTrim
|
Button7
|
Trim
|
Button8
|
Len
|
Button9
|
String
|
Button10
|
Instr
|
Button11
|
Replace
|
Button12
|
Split
|
Button13
|
Join
|
Button15
|
StrRiverse
|
Button16
|
StrConv
|
Button17
|
StrComp
|
Button18
|
Space
|
Button14
|
Exit
|
Button19
|
Setelah
Selesai Mengatur property diatas lalu masukkan listing program berikut ini.
Public Class string_versi_rama
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'LCASE(x)
=> diguakan untuk merubah huruf besar menjadi huruf kecil
Dim x As String =
text1.Text
text2.Text = LCase(x)
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
'UCase(x)
=> digunakan untuk merubah huruf kecil menjadi huruf besar
Dim x As String =
text1.Text
text2.Text = UCase(x)
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
'Left(x,n)
=> digunakan mengambil karakter dari kiri sebanyak "n"
Dim x As String =
text1.Text
text2.Text = Strings.Left(x, 3)
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
'Right(x,n)
Digunakan untuk mengambil karakter dari kanan sebanyak "n"
Dim x As String =
text1.Text
text2.Text = Strings.Right(x, 3)
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
'Mid (x,y,n)
digunakan untuk mengambil karakter x dimulai dari y sebanyak n
Dim x As String =
text1.Text
text2.Text = Strings.Mid(x, 1, 2)
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
'LTrim =>
digunakan untuk menghapus karakter spasi di bagian kiri dari string x
Dim x As String =
text1.Text
text2.Text = Strings.LTrim(x)
End Sub
Private Sub Button7_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
'RTrim =>
digunakan untuk menghapu s karakter spasi di bagian kanan dari string x
Dim x As String = text1.Text
text2.Text = Strings.RTrim(x)
End Sub
Private Sub Button8_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
'Trim =>
digunakan untuk mengapus spasi di bagian kanan dan kiri string x
Dim x As String =
text1.Text
text2.Text = Strings.Trim(x)
End Sub
Private Sub Button9_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
'Len
digunakan untuk menghitung jumlah karakter x
Dim x As String =
text1.Text
text2.Text = Strings.Len(x)
End Sub
Private Sub Button10_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
'String(x,n)
=> di gunakan untuk membuat karakter x sebanya n
Dim x As String =
text1.Text
text2.Text = New
String(x, 2)
End Sub
Private Sub Button11_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
''Space(n)
=> digunakan untuk karakter spasi sbanyak n
'Dim x As
String = text1.Text
'text1.Text =
Space(2)
'Instr(x,n)
digunkan untuk mengetahui posisi karakter n di dalam string x
Dim x As String =
text1.Text
text2.Text = Strings.InStr(x, "a")
End Sub
Private Sub Button12_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
'Replace(x,y,n)
di gunakan untuk mengganti karakter y dalam string x dengan karakter n
Dim x As String = text1.Text
text2.Text = Strings.Replace(x, "a", "o").Replace("i", "o").Replace("u", "o").Replace("e", "o")
End Sub
Private Sub string_versi_rama_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button13_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
'Split(x,n)(i)
, digunakan untuk memecah string x berdasarkan karakter n dengan penomoran i
Dim x,
y As String
x = text1.Text
y = Strings.Split(x, ",")(0)
y = Strings.Split(x, ",")(1)
text2.Text = y
End Sub
Private Sub Button14_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
Dim x As String =
text1.Text
text2.Text = Strings.Space(10)
End Sub
Private Sub Button15_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
' Join(x,n) , digunakan untuk menggabungkan
rangkain string x yang dihubungkan dengan string n
Dim x As String
x = text1.Text
text2.Text = Strings.Join(New Object() {x}, "&")
End Sub
Private Sub Button16_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
'StrReverse(x)
, digunakan untuk membalikkan posisi huruf dalam string x
Dim x As String =
text1.Text
text2.Text = Strings.StrReverse(x)
End Sub
Private Sub Button17_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
'StrConv(x,n)
, digunakan untuk mengubah huruf dalam string x berdasarkan nilai n
Dim x As String =
text1.Text
text2.Text = Strings.StrConv(x, 1)
End Sub
Private Sub Button18_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button18.Click
'StrComp(x,y,n)
, digunakan untuk membandingkan string x dan string y berdasarkan n.
' Jika n
bernilai 0 maka akan dibandingkan secara case-sensitive,
' sedangkan
jika n bernilai 1 maka akan dibandingkan secara biasa
Dim x,
y As String
x = text1.Text
y = Strings.StrComp(x, x, 0)
y = Strings.StrComp(x, x, 1)
text2.Text = y
End Sub
Private Sub Button19_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button19.Click
Me.Close()
End Sub
End Class
Komentar Anda :