string processing and regular expressions

Source: Internet
Author: User
Tags float number

Function: The output of netstat-n in CMD is collated as the original string.


Import consolevar f = io.popen ("Netstat -n"  ) Var str = f.read (  -1 )//Direct output Chinese will be garbled, so first convert Str2 = string.fromto (str,936,65001) f.close (); Io.open ();  // Open Console//io.print (str2);  //Output All results var m1 = string.match (str2, "\s*<\a\a\a>\s*<\d*\p\d *\p\d*\p\d*\p\d*>\s*<\d*\p\d*\p\d*\p\d*\p\d*>\s*\u{4,}[d] Var m2 = string.match (STR2, "\s*<\a\a\a>\s*<\d*\p\d*\p\d*\p\d*\p\d*>\s*<\d*\p\d*\p\d*\p\d*\p\d*>\s*\u{4,}\p\u{2,}[t]") Var getnum = console.getnumber ("Choose to get a connection:1.  an established connection;2.  the primary (being) closed connection") if (getnum ==  1) {Console.log (String.Replace (M1, "\u{4,}[d", "established")) Var m11 = string.fromto (m1,65001,936) String.save ("C:\establish.txt", M11,true)};else {console.log (String.Replace (M2, "\s*\u{4,}\p\u{2,}[t", "Closed ")) Var m22 = string.fromto (m1,65001,936) string.save (" C:\finish.txt ", M22,true)}console.pause ( True


Notes:

1. The string can be taken as an array length. All of them are stored in byte-code pure. Therefore, a is represented as 97 in the traversal.

2. Each variable has its own data type. The strings are all caused by ' ', so num = 123 and num = ' 123 ' are different. Can be seen with type (VAR). You can also use type.string to judge.

3. In the "+" arithmetic operation, the compiler will first try to convert the content into Number type, and then do the operation, the conversion is not an error. If you just want to connect the two values, use "+ +". Summarize the situation + will be the content as a number to do, first convert to number,++ will be directly converted to string, and then splicing together.

4. For the number type, you can directly enter other characters, such as num=0xff,0x9, as long as there is 0x in front, it is recognized as 16 binary. It is also very simple to define the way to make a binary, such as binary with var = 2#10, and the character after the # is processed into the binary format of the # front. Finally, the output will be displayed on the screen as 10 binary

Just indicates a positive number, which is an unsigned count. If you want to use a signed number to represent positive negative numbers, add a bit to the front, an int, and a maximum of 4 bytes, or 32 bits. Decimal, or float number, the number of bytes is flipped, denoted by 64 bits, that is, 16 byte.

5. The signifier: "\", in single quotation marks, \ can be used as a signifier. is recognized as a string in double quotation marks. such as str= ' \ t ' means a bit tab, with str= "\ t" is output \ T. Use ' \ n ' to represent line breaks. If you can wrap the line in double quotes, the entered carriage return is printed as-is. '% ' represents the terminator. The interpreter no longer reads backwards after reading this character.

6.unicode characters (encoded in UTF16, 16 bytes, 2 characters to represent a string): denoted by \u followed by 4 16 decimal digits. Or, at the end of the string with a u:str1= ' Kanji utf16 ' u, which represents the generation of UTF16 string, without U is a UTF8 string str2= "Kanji UTF8". When the two variables are output in Console.log (STR1,STR2), Aardio automatically converts the ANSI encoding that is supported by the console, otherwise one is utf8, and the other is UTF16, which will be garbled.


Similarly, when iterating through a utf16 Unicode character, it is #str/2, and the string subscript operator returns a Unicode code representing 2 bytes.


7. Double quotes are represented in a string, which can be used in 3 ways: 1. Use an inverted quotation mark; 2 use two "" to denote a "; 3. Assign a comment string to a string variable.

8. How to read in a file:

The essence is the way to assign values through strings:

var str = $ "C:\Desktop\ document. txt";

This allows you to assign the contents of this document,. txt, to Str. Also, support for direct drag-in. Other files, than slices, can also be dragged in this way directly. Such as:

Winform.image = $ "c:\desktop\1,jpg", Aardio will process this image into binary direct packaging.

9. Direct subscript: With two pairs of brackets: [[]]: Used in the string for traversal, output one character at a time, instead of the number of encodings corresponding to this character.

10. String conversion: str = String.tounicode (str,950) represents the conversion of a BIG5 encoded STR into Unicode mode. You can also convert from Unicode to other, such as str = String.fromto (str, first code page, second code page) so that one code can be converted to another.

11. String interception: String.left (str,3) indicates that 3 bytes are taken from the left, and a true function is required if three characters are to be taken: String.left (str,3,true)

12. The string is not modified, and the constant memory is not modifiable, but you can use the String.Replace method to regenerate one:

str = ' string '

STR2 = String.Replace (str, "a", "D")

13.UTF-8 encoding is variable-length encoding, a small number of Chinese characters are stored in 3 bytes, most of them are stored in 4 bytes, but each of his bytes is definitely greater than 16 x80, that is, more than x80 are multibyte. The default string in Aardio is UTF8 encoding.


14. Matching mode only gets the first match to the result, if you want to match multiple times, you need to use String.gmatch ()

This article from the "One Night Off" blog, declined to reprint!

string processing and regular expressions

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.