(Original) class similar to .NET in StringBuilder

xiaoxiao2021-03-06  113

I have written the ASP.NET program to know that ASP.NET provides a StringBuilder class, which is a bit similar to the String stream of Java, which is similar to the string variables in the ASP. But if more data is more, such String processing is much better than dynamic string variables! For specific reasons, you can see this article [Improve string processing performance in the ASP application]. And I wrote "template class" will sometimes connect a lot of data. Use. So I wrote this class similar to StringBuilder. But I tested the running time using this class and doesn't use the class. I found that there is no difference (maybe I have not much data in the test, I can't feel it. I can use or modify this class if you are interested, you can use it. If you modify this type, you will have a program to give me. Thank you :)

<% '/ * ====================================' / * Author: Dead in the water Fish '/ * Date: July 11, 2004' /*blog:Http://blog.lznews.cn/blog.asp?name= Wowfish '/ * Version: 1.0' / ​​* class method: ' / * DIM objString '/ * set objString = new stringbuilder' / * objstring.initisize = 1024 '/ * objString.increaseSize = 100' / * objString.Append "Add String" '/ * Objstring.insert "Insert string" 20 '/ * response.write objString.Tostring' / * objString.clear '/ * objString.Append "Second Add String"' / * response.write objString.toString '/ * set objstring = Nothing' / * When reprinting or modifying, please respect the author's intellectual property rights, keep this explanation! '/ * ============================== ======== Class StringBuilderPublic Initisize 'IncreaSize' Public Increase 'PRIVATE S_SPACESTRING' Cache Variable Variable Variable Variable Variables used by Supreme S_Position 'Used to mark the currently adding strings PRIVATE S_MAXSIZE 'Used to mark the size of the current cache variable

Private sub class_initialize initisize = 5120 'Default big space is 5K size increasesize = 512' Default Each increased size space is 0.5k s_spacestring = "" End Sub

'/ * ====================================================================================================== ingitizespace ()' / * Function role: Identified S_SPaceString's large space '/ * entry parameter:' / * Return value: '/ * ======================== ============ Private subinitiAlizespace () is less than 100byte, press the default value if INITSIZE <100 THEN INITISIZE = 5120 end if 'increased by less than 10Byte by default if increasize <10 THEN INCREASESIZE = 512 end if if s_spacestring = "" "" "" "" "" "" s_position = 0 s_maxsize = initisize end ============================================================================================================================================================================= ================ / * Function name: Increasespace (isize) '/ * function role: Add a buffer class cache space' / * Entit parameters: isize = To add characters String size '/ * Return value:' / * Description: Isize is incorporated by reference by byref, so no additional new string '/ * ============= ======================= Private subincespace (byref isize) if isize <1 thring = s_spaceString & space (isize) s_maxsize = s_maxsize isizeend Sub

'/ * ================================================================================================================================================================================================ # / * Function Role: Add a string in the cache space '/ * Entrance parameter: sstring = String' / * Return Value: '/ * Description: SSTRING Press byref to incorporate by address, so In addition, add new string '/ * ==================================== ========= public sub append (Byref sstring) DIM ILEN, PSIZE CALL INITISESPAESPACE 'If the cache variable is freate space size llen = len (sstring) psize = Ilen s_position if psize> s_maxsize kil If you want to add a string is more than the current cache variable If there is a large space, the increase in space IF (psize-s_maxsize)

'/ * =============================================' / * function name: Insert (SSTRING, IPOS ) '/ * Function effect: Insert string Cache space' / * Entit parameters: SSTRING = String IPOS = To insert Location '/ * Return Value:' / * Description: SSTRING This is by Byref It is incorporated by address, so no additional new string '/ * =============================== ===== Public Sub Insert (ByRef sString, ByVal iPos) Dim iLen If iPos> S_MaxSize then iPos = S_MaxSize End if iLen = Len (sString) S_SpaceString = Left (S_SpaceString, iPos) & sString & Mid (S_SpaceString, iPos 1) S_MaxSize = S_MAXSIZE ILEN IPOS = IPOS ILEN if ipos> s_position the "If the position of the inserted string is greater than the cache" pointer "position," pointer "S_Position = ipos end ifend sub '/ * ===== ======================================================================================================================== # / * Entrance parameters: '/ * Return value: After the processed SString value' / * description: '/ * ========================= =========== public function toString () TOSTRING = Left (s_spacestring, s_position) End Function

'/ * ============================================' / * function name: clear () '/ * Function Role: Empty the previous data, re-corrected '/ * Entrance parameters:' / * Return value: '/ * Description:' / * ================= =================== Public Sub clear () s_spaceString = SPACE (Initisize) s_position = 0 s_maxsize = initisimend subsprivate sub coplass_terminate s_spacestring = "" End Subend Class%>

转载请注明原文地址:https://www.9cbs.com/read-125596.html

New Post(0)