Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MyString = "1234567890"
MyString = "1234567890"
MyString = "1234567890"
startPos = 3
charCount = 4
Modify Characters Within a String
You can use Mid$ to modify a substring within a string.
MyString = "1234567890"
startPos = 3
charCount = 4
Mid$(MyString,startPos,charCount) = "XXXX"
MyString = "1234567890"
Fixed-Length Strings
Fixed length strings are automatically filled with spaces to pad them to their fixed-length.
When working with fixed-length strings, you can use RTrim$ to trim the extra spaces. (See
example below.)
If a fixed-length string is declared, it will be filled with Null characters until it is used. The
Visual Basic trim functions (RTrim$, LTrim$, and Mid$) will not trim Null characters, so be
sure to assign a fixed-length string to an empty string "" immediately.
Dim MyString As String * 10
string1 = "Alaska"
string2 = "California"
result = StrComp(string1,string2,vbTextCompare)
b = StrConv(company,vbFromUnicode)
' We now have a byte array containing 'C', 'H', 'I', 'L', ...
Dim s As String
Dim b(1 To 3) As Byte
b(1) = Asc("A")
b(2) = Asc("B")
b(3) = Asc("C")
s = StrConv(b, vbUnicode)
Dim s As String
s = "ABC"
For i = 1 To 6
b(i) = AscB(MidB(s, i))
Next
Dim v As Integer
v = Val("Nothing")
s = "$120.15"
Dim cc As Currency
cc = CCur(s)
Dim d1 As Date
Dim d2 As Date
Dim d3 As Date
Dim d1 As Double
Dim d2 As Double
' You can be explicit
d1 = CDbl("12.2")
Dim s As String
s = "Chilkat Software"
Dim s As String
s = "Chilkat Software"
Dim s As String
' The Like operator pays attention to the current Option Compare setting.
' Setting it to text makes the pattern matching case-insensitive.
Option Compare Text
' Use Option Compare Binary for case-sensitive string pattern matching.
' Option Compare Binary
' The Like string operator provides string pattern matching in Visual Basic.
' * matches zero or more of any character.
' ? matches any single character.
' # matches any single digit.
' Match ranges of characters by enclosing the range in brackets:
' [A-C] Matches any of A, B, or C
' [ABC] Same as [A-C]
' Match characters not in a range by using !
' [!A-Z] Any character not including A-Z
Dim s As String
s = "Chilkat Software 1234 ABCD"
String Replacement
This example shows how to do string replacement in Visual Basic.
Dim s As String
s = "Chilkat Software, Inc. : A software components company"
Dim s As String
s = "Chilkat Software, Inc. : A Software Components Company."
Dim words() As String
Dim s As String
s = "Chilkat Mail, ActiveX Component, $99, free upgrades, 1-Year Support"
' Split the string at the comma characters and add each field to a ListBox
fields() = Split(s, ",")
For i = 0 To UBound(fields)
List1.AddItem Trim$(fields(i))
Next
Dim s As String
If StrPtr(s) = 0 Then
Print "Not initialized!"
Else
Print "String is initialized."
End If
s = "123"
If StrPtr(s) = 0 Then
Print "Not initialized!"
Else
Print "String is initialized."
End If