Fostering Friendships - Enhancing Social Bonds in the Classroom
Vb.net string class visual Basic .net
1. AUTHOR: MOHAMMED ABDEL KHALEQ DWIKAT EMAIL:dwikatmo@gmail.com
TOPIC: VB (I) / ARITHMETIC LOGICAL OPERATIONS DATE: 1/31/2020 PAGE: 1 OF 5
VISUAL BASIC (II)
AN NAJAH NATIONAL UNIVERSITY
MANAGEMENT INFORMATION SYSTEMS
PREPARED BY :
MOHAMMED ABDEL KHALEQ DWIKAT
dwikatmo@najah.edu
facebook.com/dwikatmo
dwikatmo@gmail.com
31/01/2020
STRING CLASS
2. AUTHOR: MOHAMMED ABDEL KHALEQ DWIKAT EMAIL:dwikatmo@gmail.com
TOPIC: VB (I) / ARITHMETIC LOGICAL OPERATIONS DATE: 1/31/2020 PAGE: 2 OF 5
STRING METHODS
Dim S as String = "Good Morning"
Method Name Value
S.Length /This is a property 12 Number of characters
S.Substring(8) ning 9th character & after it
S.Substring(5, 3) Mor Start from 6th , 3 chars
S.Replace("o", "i") Giid Mirning Replace o with i
S.Remove(1, 2) Gd Morning Remove 2nd 3rd letters
S.ToUpper() GOOD MOORNING Change to CAPS
S.ToLower() good morning Change to Small
S.indexOf("d") 3 Location of d
S.IndexOf("o") 1 Location of 1st O
S.LastIndexOf("o") 6 Last location of o
S.Trim() Remove spaces around S
String.concat("Al","i") Ali Concating 2 texts
String.compare("a","b") False Compare 2 values
String.compare("a","a") True
String.compare("a","A") Depends on ??
S.Length : Gives the number of symbols/characters
S.Substring(8) : gives the 8th character and any leading characters
S.Substring(5, 3) : Gives 3 characters starting from position 5 –
included which are (6th,7th, and 8th characters)
S.Replace("o", "i") will replace the o with i
S.Remove(1, 2) : will remove 2 characters starting from position 1
(2nd character -Included) which are oo
S.indexOf("d"): will give the location of first occurrence of the
letter specified.
S.LastindexOf("d"): will give the location of last occurrence of the
letter specified.
S.IndexOf("o", 2): will give the position of o starting from
position 2
S.Trim(): Removes spaces before and after a string for example if s =
" Good ",its value after trim will be "Good"
3. AUTHOR: MOHAMMED ABDEL KHALEQ DWIKAT EMAIL:dwikatmo@gmail.com
TOPIC: VB (I) / ARITHMETIC LOGICAL OPERATIONS DATE: 1/31/2020 PAGE: 3 OF 5
Method Name What it does
S.Insert(3, "W") Insert letter W, in 4th location
S.Remove(5, 4) Remove 4 characters starting at 6th location
S = S.Replace("A", "H") Replace any A with H
Dim S As String
S = "Two or more Students"
T1.Text = S & vbCrLf
S = S.Insert(11, " distinct")
T1.Text = T1.Text & S & vbCrLf
S = S.Remove(0, 7)
T1.Text = T1.Text & S & vbCrLf
S = S.Replace("S", "s")
T1.Text = T1.Text & S & vbCrLf
T1.Text = T1.Text.Replace("i", "O")
As Textbox is considered as a class, its Text value also is considered
as a class, so we can treate all previous methods and apply them on
T1.text as follows
You can replace any string variable above by T1.text
In T1, replace ant I with O
T1.Text = T1.Text.Replace("i", "O"), and so on for other methods.
Change all content of T1 to Capital Letters
T1.text=T1.text.ToUpper
Change all content of T1 to Small Letters
T1.text=T1.text.ToLower
Extra methods that applied to T1 directly (but not to a string
variable or T1.text)
Having a textbox T1, then
Method Name What it does
T1.cut() Cut the selected text in t1 and saves it in clipboard
T1.copy() copy the selected text in t1 and saves it in clipboard
T1.paset() Paste the text from clipboard into current location in t1
T1.clear() Clears/deletes all the contents of T1
Create a textbox on a form, implement the previous methods on it.
4. AUTHOR: MOHAMMED ABDEL KHALEQ DWIKAT EMAIL:dwikatmo@gmail.com
TOPIC: VB (I) / ARITHMETIC LOGICAL OPERATIONS DATE: 1/31/2020 PAGE: 4 OF 5
Question: Validate an email address to be valid before leaving a
textbox, if it is not correct, go back to T1.
Email address like dwikatmo@najah.edu
Write a function that counts the occurrences of a specified character
in a string.
For example, if we have s = "duplicate id’s is done by adding the
same id as many times as we can", and we want to count how
many d exist in S. the output will be
The function returns d occurred 6 times
Write a function that validate a Jawwal phone number written in a
textbox, valid phone number as 0599565816.
First 3 characters should be 059
Total number of digits should be 10 exactly.
How to deal with numbers as text
Numbers could be treated as text (Not vice versa)
Question: having a three digit number like 784, find ones here it is
4,tens here it is 8, and hundreds here it is 7 of that number
784 = 7 hundreds + 8 tens + 4 ones
Dim N As Integer, S As String
N = Val (T1.Text)
S = N.ToString("00#")
Dim Ones As Byte, Tens As Byte, Hundreds As Byte
Ones = S.Substring(2, 1)
Tens = S.Substring(1, 1)
Hundreds = S.Substring(0, 1)
You can solve it recursively buy using Mod
Function SumDigits(N As Integer) As Integer
Dim Temp As Integer, Remainder As Integer
Temp = N Mod 10
Remainder = (N - Temp) / 10
If Remainder = 0 Then Return Temp
Return Temp + SumDigits(Remainder)
End Function
Question: depending on previous question, write a function NumToWord
that Accept a 3-digit integer number, then return its equivalent in
English words as string. For example the function will accept 784 as
parameter, and return a string which is Seven Hundreds eighty four
5. AUTHOR: MOHAMMED ABDEL KHALEQ DWIKAT EMAIL:dwikatmo@gmail.com
TOPIC: VB (I) / ARITHMETIC LOGICAL OPERATIONS DATE: 1/31/2020 PAGE: 5 OF 5
Hint: You may create 3 functions and gather the result or one function
with an array of individual numbers by using a loop.
Reverse Integer 5478 becomes 8745
Function ReverseInteger(N As Integer) As String
Dim Temp As Integer, Remainder As Integer
Temp = N Mod 10
Remainder = (N - Temp) / 10
If Remainder = 0 Then Return Temp
Return Temp & ReverseInteger(Remainder)
End Function