Beruflich Dokumente
Kultur Dokumente
Use the Visual Basic functions LTrim$, RTrim$, and Trim$ to trim whitespace from a string. MyString = " Chilkat Software " Print LTrim$(MyString) ' prints "Chilkat Software " Print RTrim$(MyString) ' prints " Chilkat Software" Print Trim$(MyString) ' prints "Chilkat Software"
String Concatenation
The string operator & performs a string concatenation.
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 fixedlength string to an empty string "" immediately. Dim MyString As String * 10 MyString = "Chilkat" ' MyString contains "Chilkat "
Print RTrim$(MyString) ' prints "Chilkat" Dim AnotherString As String * 10 Print Len(RTrim$(AnotherString)) ' Prints 10, because the string contains Null characters.
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" ' Relace all occurances of a substring, case sensitive s = Replace(s, "software", "hardware") ' prints "Chilkat Software, Inc. : A Hardware Components Company" Print StrConv(s, vbProperCase) ' Replace all occurances, case-insensitive s = "Chilkat Software, Inc. : A software components company" s = Replace(s, "software", "hardware", 1, -1, vbTextCompare) ' prints "Chilkat Hardware, Inc. : A Hardware Components Company" Print StrConv(s, vbProperCase) ' Replace only the 1st occurance, case-insensitive startPos = 1 maxToReplace = 1 s = "Chilkat Software, Inc. : A software components company" s = Replace(s, "software", "hardware", startPos, maxToReplace, vbTextCompare) ' prints "Chilkat Hardware, Inc. : A Software Components Company" Print StrConv(s, vbProperCase)