1 / 14

Regular Expression ASCII Converting

Regular Expression ASCII Converting. Regular Expression. Regular Expression is a tool to check if a string matches some rules. It is a very complicated topic. We only give some basic rules here. Suppose that ~ means match. Then expression d means a digital number. So

zanthe
Télécharger la présentation

Regular Expression ASCII Converting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Regular ExpressionASCII Converting

  2. Regular Expression Regular Expression is a tool to check if a string matches some rules. It is a very complicated topic. We only give some basic rules here. Suppose that ~ means match. Then expression \d means a digital number. So "2" ~ \d "77023" not ~ \d If we want to match more digital numbers, we have "77023" ~ \d+ If we want to match exact 5 digital numbers, have "77023" ~ \d{5} Here {5}means repeating 5 times. expression \w means any letter of a-z or A-Z or 0-9 and_ expression \s means white space.

  3. Regular Expression Definitions [ ] means any one, ( ) means all of them $ #

  4. More Definitions

  5. Regular Expression (RE) examples The zip code three formations: 77023 77023-4578 77023 4578 So we first has expression \d{5} for 77023 Then we have either – or white space or none So it is [\s-]? The last 4 digits is optional, so is (\d{4})? or ([0-9]{4})? Thus we got \d{5}([\s-]\d{4})? The email address like tand@uhv.edu Its RE is \w+@(\w+\.)+\w{2,3}

  6. The telephone number could be: 713-567-3491 or (713)567-3491 (713) 567-3491 RE of 713-567-3491 is \d{3}-\d{3}-\d{4} RE of (713)567-3491 and (713) 567-3491 \(\d{3}\)\s?\d{3}-\d{4} So combine the together, we have (\(\d{3}\)\s?|\d{3}-)\d{3}-\d{4}

  7. Class Regex and Match • Using System.Text.RegularExpressions; • Class Regex object is used to search regular expression in the string. • The constructor is Regex(string RE) the argument RE is the regular expression • Basic operator is Match Match(string str) the argument str is the string to be searched the return value is Match object • Match ::Success Success ==true means found match • Match :: Index is the position of the match

  8. Example Regex r = new Regex("\d[a-z]"); Match m = r.Match("123gabc456"); if (m.Success) { Response.Write("Found match at position " + m.Index); }

  9. Replace operators for string string str = "Can you lend me your car?"; string str2 = str.Replace("you", "he"); Then str2 = "Can he lend me her car?"; However, if use regular expression replace string str3 = Regex.Replace(str, @"you\b", "he"); Then str3 = "Can he lend me your car?"; The regular expression string must prefix @

  10. Char and byte converting • Every byte is 8 bits, so its range is from 0 to 255. • If the first bit is 0, the byte is used to express characters. Some character is not written- able, such as space. • Convert a single Character is easy Char ch = 'A'; int n = (int)ch; Char c = (Char)99;

  11. ASCII Table (0-63)

  12. ASCII Table (64-127)

  13. String and byte array Converting We can convert string to an byte array and vise versa. The converting object is ASCIIEncoding asciiConvertor = newASCIIEncoding(); The name space is System.Text We need to use two major functions: byte [] GetBytes(string msg); and string GetString( byte[]data, intoffset, int Length);

  14. Data Structure object There are three major data structure objects (I) ArrayList the major operation is Add(…) and Remove() (ii) Stack the major operation is Push(…) and Pop() (iii) Queue the major operation is Enque(…) and Deque() Their name space is System.Collections. Note: They must add class objects. Any element read from those structure class object need cast to get the oringinal class data type.

More Related