In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, Xiaobian will bring you about how to analyze the application method of VB. NET Mid function. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
VB. NET programming language, there are many functions of the application is more complex, we need through continuous practice, accumulated experience to master skillfully, and correctly apply them in the program to complete our needs. Here we will introduce you to the VB. NET Mid function related applications.
The VB. NET Mid function is generally used to return substrings of the original string, such as
Dim MyString, FirstWord, LastWord, MidWords MyString = "Mid Function Demo" Creates a string. FirstWord = Mid(MyString, 1, 3) 'returns "Mid". LastWord = Mid(MyString, 14, 4) 'returns "Demo." MidWords = Mid(MyString, 5) 'returns "Function
Specific functions are described as follows:
Returns Variant (String) containing the specified number of characters in the string.
syntax
Mid(string, start[, length])
The syntax of the Mid function has the following named parameters:
VB. NET Timer Implementation Function Details
Analysis of Specific Functions of VB. NET Monitoring Class
VB. NET Error Resolution Summary
Analysis of VB. NET Initialized Grid Implementation Method
Discussion on the Method of Obtaining Current URL in VB. NET
string
Required parameters. A string expression from which characters are returned. If string contains Null, Null is returned.
start
Required parameters. for Long. The character position of the extracted part of string. If start exceeds the number of characters in string, the VB. NET Mid function returns a zero-length string ("").
length
Optional parameter; is Variant (Long). Number of characters to return. If the omission or length exceeds the number of characters in the text (including the character at start), all characters in the string from start to tail are returned.
description
To know the number of characters in string, use the Len function.
Note that the MidB function works on byte data contained in a string, as in the double-byte character set (DBCS) language. Therefore, its parameters specify the number of bytes, not the number of characters. For sample code that uses MidB, see the second example in the Sample topic.
So can we use it to make some string substitutions? Run the following function on your machine:
Option Explicit Public Function Test() As String Dim s As String s = "ABCD" Mid(s, 1, 1) = "T" Test = s End Function
What did you find? WOW, the output string becomes "TBCD"! Yes, we can use the VB. NET Mid function to replace strings (very happy thing)! So what if I changed "T" to "TX"? Please see the following code:
Option Explicit Public Function Test() As String Dim s As String s = "ABCD" Mid(s, 1, 1) = "TX" Test = s End Function
Run it again, and as expected, it's "TBCD." Although the VB. NET Mid function can do some simple string substitution, it does so on condition that the string does not exceed its return length (1 in this example). So some people might ask, what happens if it's less than its return length? Well, that's a good idea, but let's let the experiment show it, see:
Option Explicit Public Function Test() As String Dim s As String s = "ABCD" Mid(s, 1, 3) = "TX" Test = s End Function
After running it, the result is as follows: "TXCD".
From the results above, Mid can do some simple string substitutions, but the following conditions must be observed:
The *** length of the replacement is determined by the *** length returned by Mid. If the length of the substitution string is greater than its return length, only the first part of the substitution string is used for substitution. If the length of the replacement string is less than its return length, then the excess of the original string is retained and the rest is replaced. Although the VB. NET Mid function has a very clever function in some cases, if it involves common string operations, it is recommended to use Replace(expression, find, replace[, start[, count[, compare]]) as much as possible.
The above is how to analyze the application method of VB. NET Mid function shared by Xiaobian for everyone. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.