Hanya sharing pengalaman: nge blog, google AdSense, cyber enjoyable

Naruto Fans Kampanye Damai Pemilu Indonesia 2009 Mendukung SBY untuk menjadi Presiden 2009-2014

Jul 6, 2007

Concatenating Strings

Visual Basic supports only one string operator, the concatenation operator. This operator combines two or more strings of text, similar to the way the addition operator is used to combine two or more numbers. The concatenation operator is the "ampersand" symbol (&). When you combine two strings with the concatenation operator, the second string is added directly to the end of the first string. The result is a longer string containing the full contents of both source strings.

The concatenation operator is used in an assignment statement as follows:

NewString = stringOne & stringTwo & stringThree

In this syntax, NewString represents the variable that contains the result of the concatenation operation. stringOne, stringTwo, and stringThree all represent string expressions. These can be any valid strings, including string variables, literal expressions (enclosed in quotation marks), or functions that return a string.

The ampersand between a pair of string expressions tells Visual Basic to concatenate the two expressions. The ampersand must be preceded and followed by a space. The syntax shows an optional second ampersand and a third string expression. You can combine any number of strings with a single statement. Just remember to separate each pair of expressions with an ampersand.

Code example:

Private Sub Command1_Click()

Dim STR1, STR2 As String

STR1 = "mas Basy"

STR2 = " Belum Makan"

Form1.Print (STR1 & STR2)

End Sub

0 comments:

Alexa Rank