giáo trình visual basic và pic phần 2

Tham khảo tài liệu 'giáo trình visual basic và pic phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Visual Basic Parsing Strings Dim sText As String Dim sMidText As String sText Reynolds Electronics sMidText Mid sText 3 8 After running this code sMidText should equal ynolds E which starts at the 3rd letter and goes through the 11th 3 8 11 . See how it works. It should also be noted that if a length is not stated it will return all characters from the starting position to the end of the string as you will see below. Putting It All Together Now for some real fun. Lets say that you are receiving data from a Basic Stamp. This data is stored in a buffer called sBuffer. Each set of data is separated by an ASCII 13. You want to be able to separate each of these sets of data one by one and display them in the debug window. Here goes. Dim sBuffer As String Dim lEnd As Long Dim sData As String This is the data in your buffer sBuffer Data1 Chr 13 Data2 Chr 13 Data3 Chr 13 Data4 Chr 13 lEnd InStr sBuffer Chr 13 Gets Starting position of ASCII 13 Do Starts the loop If lEnd 0 Then If 0 then we have an ASCII 13 in the buffer sData Left sBuffer lEnd - 1 sData will be all characters before lEnd sBuffer Mid sBuffer lEnd 1 We want to delete the data that we just got from the buffer including the ASCII 13 sData Display the data lEnd InStr sBuffer Chr 13 Gets Starting position of ASCII 13 in the new buffer End If Loop While lEnd 0 Loop while ASCII 13 is still present in the buffer After running this code you should see Data1 through Data4 show up in your Debug Window. http 4 of 5 5 25 2004 8 47 51 PM Visual Basic Parsing Strings String manipulation is not really that hard. With the use of theses four functions you can parse any string that you want to. It just takes some planning as to how the data will be presented to you and how you should go about getting the data that you want out of the big string. - Data Types Intro Advanced Parsing Copyright 1999-2001 Reynolds Electronics Contact Information Reynolds Electronics 3101 Eastridge .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.