TechCSE: VB String

Sunday, 30 October 2011

VB String


VB String
Strings are synonymous with text. Values stored in a string placed in into text properties, or any
property that holds textual values. String variables are able to store any kind of data like
text,number,symbols. In VB we define string as String.
Declaring :
Strings are 2 types, Variables and fixed size. A variable size string can hold about two-billion
characters ans a fixed size string can hold sixty-four thousand characters. A variable string can defined
as
Dim str1 As String
Private str2 As String
And a fixed size string can defined as
Dim str3 As String * 6
Dim str4 As String * 7
6,7 means the string size.
Converting String :
Asc(“?”) :
Asc means the ASCII(American Standard Code for Information Interchange ) Code. By this
code we can see the ASCII code of the any string.
Dim intStr As Integer
intStr = Asc(“?ABC”)
Chr :
Chr () function is just opposite of Asc(). It gives the character code of any number.
Dim str As String
str = Chr(64)
Str :
It takes a numerical value(Long) and converts it into string type.
Dim str As String
str = str(300)
Concatenation :
Using & operator :
Using “&” operator we can join two strings,like
str = “hello” & “world”
Using + operator :
Using this we can also join two string but make sure that both are integer. Like
“4.5” + “2”
Formating Strings:
Lcase/UCase :
Using Lcase we can we can convert all the string into lower case and using Ucase we can
convert all case into upper.
str1 = “HI HOW ARE YOU?”
str2 = LCase (str2)
str3 = “i am fine”
str4 = Ucase(str3)
StrConv :
To make the string as you want, you can use the StrConv function.Constant
vbUpperCase
vbLowerCase
VbProperCase
Value-Description
1-Converts into uppercase.
2-Converts into lowercase.
3-Converts first letter of the string into capital.
Format :
The Format function can use in various ways. It can be used to format strings that holds
number,date,time & text values. Syntax of this is
Format(expression[, format])
str1 = Format(Time,”Long Time”) Returns the current date.
str2 = Format(5999.90, “##,##0.00) Returns 5,999.90
Manipulation String :
Len (string) :
Find the length of the given string. What is the string length,we can find out by this command
easily. Len(“My name is Arnab.”) It would return 16.
Space() /String() :
To add a number of space or repeat a character many times,we use Space operator.
Str = Space(15)
This code sets the variable str equal to15.
Str2 = String(10, “X”) & intMyNumber
This code means the first 10 space will be X and then print the integer. Here & is joining two variables.
Comparing Strings :
Strcomp :
It compares the two given strings. Like
StrComp(“abcd” , “abcd”)
Return Value
-1–>str1 < str2
0–>str1 = str2
1–>str1 > str2
NULL–>Both strings are NULL
Option Compare :
This states how the string are compared within a module. This statement must appear before any
procedure.
Option Compare (Binary | Text | Database)

Home
Copyright © TechCSE Urang-kurai