OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Strings 48<br />
ensures that the MyString string is initialized with the value of the number 13, which<br />
stands for a hard line break.<br />
The Chr command is often used in Basic languages to insert control characters in a string.<br />
The assignment<br />
MyString = Chr(9) + "This is a test" + Chr(13)<br />
therefore ensures that the text is preceded by a tab character (Unicode-value 9) and that a<br />
hard line break (Unicode-value 13) is added after the text.<br />
Accessing Parts of a String<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic provides three functions that return partial strings, plus a length<br />
function:<br />
Left(MyString, Length)<br />
returns the first Length characters of MyString.<br />
Right(MyString, Length)<br />
returns the last Length characters of MyString.<br />
Mid(MyString, Start, Length)<br />
returns first Length characters of MyString as of the Start position.<br />
Len(MyString)<br />
returns the number of characters in MyString.<br />
Here are a few example calls for the named functions:<br />
Dim MyString As String<br />
Dim MyResult As String<br />
Dim MyLen As Integer<br />
MyString = "This is a small test"<br />
MyResult = Left(MyString,5) ' Provides the string "This "<br />
MyResult = Right(MyString, 5) ' Provides the string " test"<br />
MyResult = Mid(MyString, 8, 5) ' Provides the string " a sm"<br />
MyLen = Len(MyString) ' Provides the value 20<br />
Search and Replace<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic provides the InStr function for searching for a partial string within<br />
another string:<br />
ResultString = InStr (MyString, SearchString)