.NET Frame Class Save (Part 2)

xiaoxiao2021-03-06  40

.NET Frame Class Save (Part 2)

(www.jojoo.net) 2001-6-5 (Please double-click the automatic scroll to watch, click Stop, then hit ..)

First, handle strings

The .NET Framework class (or SYSTEM class) provides a large number of core functions that can be used when constructing .NET applications, which apply to any locale. The first part of this article describes the basic concepts such as assemblies, namespaces, and System.math and System.random classes. This is the second part of this article, then discuss several other useful classes: System.String, System.Array, System.DateTime.

It is worth pointing out that as mentioned above, when we use VB.NET as a programming language, we often face this option: use the VB.NET language built-in function, or uses the equivalent SYSTEM class Features. We face this option when processing arrays, date / time, string data. If you used to be a VB 6.0 programmer, your first choice may be inspected and active. However, if possible, you'd better change the old habits and use the new .NET System class. why? Because the System class is used to make your code easier to port to other .NET languages ​​and future VB.NET versions.

The SYSTEM.STRING class provides a wealth of string processing capabilities. Using the System.String class, we can: determine the length of the string, find the substrings, change the case of the string, compare two strings, split strings, and more.

Determine the length of the string is the length property. For example, in the following code, the value of intlength will be 4:

DIM STRCOLOR As String = "Blue" DIM INTLENGTH AS INTEGER INTLENGTH = STRCOLOR.LENGTH

We use the indexof method to find the first matching substring from the string. If the substring is found, the indexof method returns the start position of the sub-string (the start position of the first character is 0); if it is not found, INDEXOF returns -1. Indexof's lookup is sensitive. IndexOf is an overload method that allows incoming parameters including: Char type characters, string type strings, Char types of characters. The following this indexof.aspx page demonstrates the use of three different parameter type IndexOf methods:

<% @ Page language = "vb" explicit = "true"%> system.string instance </ title> <script language = "vb" runat = "server"> SUB Page_load (src as object, E AS Eventargs) DIM Chrg As Char = "G" DIM STRWORD AS STRING = "for" Dim Chrvowels As Char () = {"A", "E", "I", "O", "U"} DIM STRPHRASE AS String = _ "One Small Step for Man, One Giant Leap for Mankind." DIM I as INTEGERLBLOUTPUT.TEXT & = "<br / STRPHRASE =" & STRPHRASE LBLOUTPUT.TEXT & = "<br /> Position of ChRG = "_ & strphone.indexof (chrg) lbloutput.text & =" <br /> POSITION OF STRWORD = "_ & STRPHRAS.IDexof (strword) lbloutput.text & =" <br /> position of chrvowels = "_ & strphrase .Indexof (chrvowels) End sub </ script> </ head> <body> <ask: label id = "lbloutput" runat = "server" /> </ body> </ html></p> <p>The result of this page is as follows:</p> <p>IndexOF allows you to specify two optional parameters for restricting search, which represent the start and end position of the search string, respectively. For example, the following code restrictions between Chrvowels between the 10th to 20 characters:</p> <p>STRPHRASE.INDEXOF (Chrvowels, 10, 20)</p> <p>The LastIndexOf method is similar to the IndexOf method, but it searches for the last appearance of the substrings. For example, if you modify the IndexOF.aspx page, use the LastIndexOF method to replace the indexof method, then the position of the strWord will be 39 instead of 15.</p> <p>Use system.string TouPper and Toolower methods to change strings to all uppercase or write. E.g:</p> <p>Strupper = "this is a mixed case senence" .toupper () strlower = "this is a mixed case senence" .tolower ()</p> <p>As can be seen from this example, the properties and methods of System.String can be applied in a string variable or directly in a string text.</p> <p>You can compare whether the two strings are the same with the COMPARE method. If the two strings are the same, the Compare method returns 0; if the first string is less than the second string, the Compare returns a negative number; if the first string is greater than the second string, the Compare method returns a positive number. Compare is a static method (see instructions on the static method and example method in front of this article). By default, Compare is sensitive to the comparison of the string and does not consider regional relationships. For example, the comparison of STR1 and STR2 will return -1, which represents STR1 less than STR2: DIM STR1 AS STRING = "abcd.com" DIM STR2 AS STRING = "Abcd.com"</p> <p>Answer = String.Compare (str1, str2)</p> <p>We can pass to Compare to the third alternative parameters. If the third parameter is specified as True, the string comparison operation ignores case, such as the value of the Answer in the code below is 0, that is, two strings equal.</p> <p>Answer = String.comPare (str1, str2, true)</p> <p>As INDEXOF methods, Compare is also an overloaded approach. We can pass to the Compare method to the fourth parameter requirements for the region-related comparison; or we can specify the start and end position of the character, making it compared to only part of the string. See the .NET Framework SDK documentation to learn more. The Split method splits the string into an array composed of subtrine. When using the Split method, we must specify segmentation characters for split strings, CHAR types. The following split.aspx page demonstrates the application of the Split method:</p> <p><% @ Page language = "vb" explicit = "true"%> <head> <title> split instance </ title> <script language = "vb" runat = "server"> SUB Page_load (SRC AS Object, e as Eventargs) DIM Strasp As String = _ "ASP.NET IS The Next Generation of Active Server Pages." DIM STRWORDS () AS STRING DIM I AS INTEGER</p> <p>StrWords = strasp.split ("")</p> <p>For i = strWords.getLowerBound (0) to strWords.getupperBound (0) lbloutput.text & = i & ":" & strwords (i) & "<bript>" Next End Sub </ script> </ head> < Body> <asp: label id = "lbloutput" runat = "server" /> </ body> </ html></p> <p>The output of Split.aspx is as follows:</p> <p>We discussed the application of String class properties and methods. String also includes many other members, such as constructing a string from an array, replacing a character in the string to other characters, deleting a gum character in front or behind, and so on.</p> <p>Second, the operating array we can process an array with a variety of methods via the System.Array class. Like several of the previous classes, many of the features of the System.String class repeats the features of the VB language. But the Array class has also added some traditional VB language, such as search and sort arrays. The GetLowerBound and GetUpperBound methods of the Array class are used to determine the lower bound and upload of the array specified dimension. The following statement comes from split.aspx (see the previous example), it determines the boundary of the strWords array via the getLowerBound and getupperBound method:</p> <p>For i = strWords.getLowerBound (0) to strWords.getupperBound (0)</p> <p>The Sort static method of System.Array can sort the contents of one-dimensional array. The Sort method is sensitive to the array of groups, and it cannot be sorted for arrays above one-dimensional. Call the syntax of the sort method:</p> <p>Array.Sort (array_name)</p> <p>For one-dimensional arrays, we can also use the Reverse method to reverse the order of array elements. The syntax of the Reverse method is similar to the sort method:</p> <p>Array.Reverse (array_name)</p> <p>The following code (from the Arraysort.aspx sample page) demonstrates the application of the Sort and Reverse methods:</p> <p>DIM STRTERMS () AS String = {"JScript", "VB", "ASP", "ASP.NET", ".NET"} DIM I AS INTEGER</p> <p>LBLOUTPUT.TEXT & = "Original Array <br />" for i = strterms.getLowerBound (0) to strterms.getupperBound (0) lbloutput.text & = i & ":" & strTerms (i) & "<br /> NEXT</p> <p>Array.Sort (STRTERMS) LBLOUTPUT.TEXT & = "<br /> after sorting <br />" for i = strterms.getLowerBound (0) to strterms.getupperbound (0) lbloutput.text & = i & ":" & STRTERMS (I) & "<br />" Next</p> <p>Array.Reverse (strTerms) lbloutput.text & = "<br /> after" <br /> "for i = strterms.getLowerBound (0) to strterms.getupperBound (0) lbloutput.text & = i &": "& STRTERMS (I) & "<br />" Next</p> <p>The output of the Arraysort.aspx page is as follows:</p> <p>The System.Array method supports searching for one-dimensional arrays with IndexOF and LastIndexOF methods, which are similar to the same name method of the System.String class. Searching the syntax of the array with indexof and lastindexof methods as follows:</p> <p>Answer = array.indexof (array_name, search_string) Answer = array.lastindexof (array_name, search_string) These two methods returned to search strings for the first time and last matching position; if they cannot be found, the return value is -1. This search is sensitive. For example, in the following code, the Answer will be 2, which indicates the third element of the string "ASP" is the STRTERMS array.</p> <p>DIM STRTERMS () AS String = {"JScript", "VB", "ASP", "ASP.NET", ".NET"} answer = array.indexof (STRTERMS, ASP ")</p> <p>Third, the Date / Time Data System.DateTime class provides many ways to process the DateTime value. To create a DateTime value, we only declare a variable of a DateTime type and give it a DateTime constant through the "#" separator, as shown below:</p> <p>DIM seattlequake as datetime = # 02/28/01 10: 54 #</p> <p>A great advantage of the System.DateTime class is that we can analyze the date / time values ​​via its attribute. The meaning of these DateTime class properties is very obvious, they are: Year, Month, Day, Dayofweek, Dayofyear, Hour, Minute, Second, Millisecond, Ticks, and so on. Each Ticks is equal to 100 nanoseconds (mik seconds). For example, in the following code, the value of the Answer will be equal to 10:</p> <p>Answer = seattlequake.Hour</p> <p>We can also use the Date and TimeOfDay properties to get date or time part of DateTime data. The TimeOfDay property returns a Timespan value that indicates that the TICKS time has been passed. Imagine that attributes using the Timespan value we can analyze the various parts of the Timespan time. See the .NET Framework SDK documentation to learn more.</p> <p>The System.DateTime class also provides several ways to add (or decrease) a part of the DateTime value, which is: AddYears, AddMontHS, AddDays, AddHours, AddMinutes, AddSeconds, AddMilliseconds, AddTicks.</p> <p>For example, the following code is added to the specified date (BDAY), minus 1 year operation:</p> <p>Dim bday as datetime = # 6/25/2001 12: 00 # DIM NEXTBDAY AS dateTime Dim Lastbday As datetime</p> <p>Nextbday = thesedate.addyears (1) Lastbday = thesedate.addyears (-1)</p> <p>【reference】</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-67968.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="67968" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.046</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'C7DQGhyNxKdAvny7uZSVdFjQ2a1PN7824fkzFSNb3nVUuzLWNdMFpBCSyIMfEknwhBbMk4jscdJRRBIZ78_2FI8A_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>