Self-write function VB6 stuff function and vb.net stuff function

Source: Internet
Author: User

‘*************************************************************************
' * * Module name: self-write function VB6 stuff function and vb.net stuff function
' * * Description: Blue Phoenix design Mall bath Fire Phoenix-Guo Wei | Blue Phoenix-Magic Spirit | Guo Wei-icecept
' * * Created by: Shower Fire Phoenix-Guo Wei
' * * Date: October 10, 2015 23:13:55
' * * Modified by: Shower Fire Phoenix-Guo Wei
' * * Date:
' * * Description: qq:493405998 | \ Wang: icecept
' * * Version: V1.0.0 | Http://blog.sina.com.cn/icecept
‘*************************************************************************

' Delete, replace, insert character VB6 stuff function

Public Function Stuff (ByVal strsourcea as String, ByVal intbeginpositionb As Integer, ByVal modifycharnumberc As Integer, ByVal Modifychard As String) as String

............
End Function


‘--------------------------------------------------------------------------------------
' Stuff function: Stuff ("original string", "Start position", "Insert (c=0), replace (c>1), delete (d=" ") Character number", "to insert (c=0), replace (c>1), delete (d=" ") characters"

' Important because the index value of the vb.6 string is starting from 1, all operations of this function are starting from 1, the maximum index value of the string is the total number of strings

' Strsourcea is the original string,
' Intbeginpositionb is the starting position, intbeginpositionb=0 default intbeginpositionb=1
' Modifycharnumberc are you going to replace? ' Delete? The number of characters inserted?
' Modifychard is the string to be modified, modifychard= "" To delete the specified character.
' modifycharnumberc=0 can insert a specified character, and when Iintbeginpositionb <= Len (strsourcea) + 1 o'clock, the character is inserted between Len (Strsourcea) + 1 in the string position
' Modifycharnumberc > 0 and Modifychard are not equal to NULL when the specified character can be substituted

----------------------------------------------------------------------------------------------

' Delete, replace, insert character vb.net stuff function

Public Class Form1

Public Function Stuff (ByVal strsource as String, ByVal intbeginposition As Integer, ByVal modifyposition as Integer, ByVal Strdestination As String) as String

..................

End Function
End Class
' Delete, replace, insert character
' Stuff function: Stuff ("original string", "Start position (zero-based index value)", "Replace, delete the number of characters (when this parameter is zero)", "to insert, replace character (delete character when this parameter is empty)"

' Important because the index value of the vb.net 2010 string is zero-based, all operations of this function start at 0, and the maximum index value of the string is the total number of strings minus one
' Strsourcea is the original string. Intbeginpositionb is the start position, default is zero, INTBEGINPOSITIONB is less than 0 o'clock, default is 0
' Modifycharnumberc is to be replaced? ' the number of characters inserted, when MODIFYCHARNUMBERC is less than 0 o'clock, the default is 0
' Modifychard is the string to be modified, modifychard= "" To delete the specified character.
' modifycharnumberc=0 can insert a specified character, and when the second argument is >=0, less than length, inserts a character between length of the string position
' Intbeginpositionb>=0 or intbeginpositionb< the original string. When length and modifycharnumberc=0 are strd= "", the Strsourcea remains intact, (equivalent to inserting an empty character at the appropriate character)
' Intbeginpositionb>=0 or intbeginpositionb< string. ' Length when,modifycharnumberc>0,strd<> ' "" can be substituted for the specified character

' ========================================================

I like to write programs, because I am learning accounting computerization, so the foxbase sentiment has a unique compromise, and later transformed into VB, one to the present use of vb.net 2010 I have been using this function, the function is very powerful, a function can ' delete, replace, insert characters. But I think the other programming language stuff function is too bad to understand, I just as I understand the VB6 and vb.net 2010 respectively wrote the stuff function, the following functions are described below.

program Example: VB6 stuff function

Private Sub Command11_click ()
Dim Str as String
The string index value of ' VB6 ' starts at 1, while vb.net 2010 's string index value starts at 0.
' Starting at the position of index value 6, replacing 2 characters with 123, i.e.: abcde123
Debug.Print Winos.stuff ("ABCDEFG", 6, 2, "123")
' Insert the character 123 at the end of the string, i.e.: abcdefg123
Debug.Print Winos.stuff ("ABCDEFG", Len ("ABCDEFG") + 1, 0, "123")
' Remove 2 characters from the location of the index value 6, i.e.: ABCDE
Debug.Print Winos.stuff ("ABCDEFG", 6, 2, vbNullString)
' When the starting position is zero, when the fourth argument is empty, 4 characters are deleted from the starting position, namely: EFG
Debug.Print Winos.stuff ("ABCDEFG", 0, 4, vbNullString)
' Start position is zero, when the third parameter is greater than zero, and the fourth parameter is not NULL, equivalent to a replacement, i.e. 123EFG
Debug.Print Winos.stuff ("ABCDEFG", 0, 4, "123")
' Insert a null character after G, i.e.: ABCDEFG
Debug.Print Winos.stuff ("ABCDEFG", 8, 0, vbNullString)
' Insert a null character before a, i.e.: ABCDEFG
Debug.Print Winos.stuff ("ABCDEFG", 0, 0, vbNullString)
' Data offside, replace nonexistent location, will output null value
Debug.Print Winos.stuff ("ABCDEFG", 8, 1, vbNullString)
' When the second parameter is less than zero, the default equals 0, and when the third argument is less than zero, the default equals 0, namely: ABCDEFG
Debug.Print Winos.stuff ("ABCDEFG",-1,-1, vbNullString)
' Insert Guo into the index value 6, i.e.: ABCDE Guo FG, when the insertion position is negative, the default is zero
Debug.Print Winos.stuff ("ABCDEFG", 6,-1, "Guo")
' Put Guo in the string to delete the result: "Hello, Guardian"
Debug.Print Winos.stuff ("Hello, Guo Wei", InStrRev ("Hello, Guo Wei", "Guo"), 1, vbNullString)
str = "Hello, Guo Wei, have you eaten?"
' Find the specified character and delete the result: "Hello, have you eaten?"
Debug.Print Winos.stuff (str, InStrRev (str, "Guo"), Len ("Guo Wei,"), vbNullString)
"Guo Wei," insert the character after "Good Morning,": Result: "Hello, Guo Wei, morning, eat?"
Debug.Print Winos.stuff (str, InStrRev (str, "Guo") + Len ("Guo Wei,"), 0, "Good Morning,")

End Sub

Private Sub Form_Click ()
Dim str1 as String
Dim I As Integer, J As Integer
str1 = "6-15-8-9-5"
For i = 1 to UBound (Split (str1, "-"))
j = InStr (1, str1, "-")
STR1 = Stuff (Str1, J, 1, ":" & I & "=")
Next
Debug.Print str1 ' 6:1=15:2=8:3=9:4=5
End Sub

Private Sub Command1_Click ()
Dim str1 as String
STR1 = Text1.Text
Dim I As Integer, J As Integer
For i = 1 to UBound (Split (str1, "*"))
j = InStr (1, str1, "*")
STR1 = Stuff (Str1, J, 1, vbNullString)
Next
Text1.Text = Str1 ' 1234567
End Sub

Private Sub Command2_Click ()
Dim s as String, I as Integer
s = "ABCDEF"
Text2.text = vbNullString
For i = Len (s) to 3 Step-1
s = Stuff (S, 3, 1, vbNullString) ' string is removed from the third character each time
Text2.text = text2.text & "s=" & S & vbCrLf
Next
' s = abdef
' s = abef
' s = ABF
' s = AB
End Sub

Private Sub Form_Load ()
Text1.Text = "1**2*3***4***56**7"
Text2.text = "ABCDEF"
End Sub

'-------------------------------------------------------------------------------vb.net stuff function

Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click

The string index value of ' VB6 ' starts at 1, while vb.net 2010 's string index value starts at 0.

' Starting at the position of index value 5, replacing 2 characters with 123, i.e.: abcde123
Debug.Print (Stuff ("ABCDEFG", 5, 2, "123"))
' Insert the character 123 at the end of the string, i.e.: abcdefg123
Debug.Print (Stuff ("ABCDEFG", "ABCDEFG". Length, 0, "123"))
' Remove 2 characters from the location of the index value 5, i.e.: ABCDE
Debug.Print (Stuff ("ABCDEFG", 5, 2, vbNullString))
' When the starting position is zero, when the fourth argument is empty, 4 characters are deleted from the starting position, namely: EFG
Debug.Print (Stuff ("ABCDEFG", 0, 4, vbNullString))
' Start position is zero, when the third parameter is greater than zero, and the fourth parameter is not NULL, equivalent to a replacement, i.e. 123EFG
Debug.Print (Stuff ("ABCDEFG", 0, 4, "123"))
' Inserts a null character at the end of the string, i.e.: ABCDEFG
Debug.Print (Stuff ("ABCDEFG", 8, 0, vbNullString))
' Data offside, replace nonexistent location, will output null value
Debug.Print (Stuff ("ABCDEFG", 8, 1, vbNullString))
' When the second parameter is less than zero, the default equals 0, and when the third argument is less than zero, the default equals 0, namely: ABCDEFG
Debug.Print (Stuff ("ABCDEFG",-1,-1, vbNullString))
' Insert Guo into the index value 5, i.e.: ABCDE Guo FG, when the insertion position is negative, the default is zero
Debug.Print (Stuff ("ABCDEFG", 5,-1, "Guo"))
' Put Guo in the string to delete the result: "Hello, Guardian"
Debug.Print (Stuff ("Hello, Guo Wei", "Hello, Guo Wei". IndexOf ("Guo"), 1, ""))
' Find the specified character and delete the result: "Hello, have you eaten?"
Dim str as String = "Hello, Guo Wei, have you eaten?"
Debug.Print (Stuff (str, str. IndexOf ("Guo Wei,"), "Guo Wei,". Length, ""))
' Insert character after ' Guo Wei ': Result: "Hello, Guo Wei, Good morning, eat?"
Debug.Print (Stuff (str, str. IndexOf ("Guo Wei,") + "Guo Wei,". Length, 0, "Good Morning,"))

End Sub

If you are interested in this function, please go to http://blog.sina.com.cn/s/blog_49f7bc810102vwzm.html to download the Blue Phoenix-Demon function library to use.

Self-write function VB6 stuff function and vb.net stuff function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.