Pattern matching of string and strings

Source: Internet
Author: User

A comparison of strings
Compare the encoding between the characters that make up the string (Unicode, ASCII)
Second, the creation of a series of data types
The logical structure of a string is similar to a linear table, except that the string is for a character set
For basic operations, there are differences from linear tables:
1. The linear table concerns the operation of a single element, such as finding an element, inserting a delete operation
2, string more is to find the location of the substring, get the substring of the specified position, replace the substring
Three, the storage structure of the string
As with linear tables, there are two types: sequential (with a contiguous set of address spaces), chained storage structure (a linked list with multiple characters in one node).

Pattern matching: Locating operations of substrings, often referred to as String pattern matching
1. Simple Pattern Matching: (do not use other operations < such as String interception, only using the array to achieve pattern matching)

 Public classdemo01{ Public Static voidMain (string []args) {string S= "Happaaaadwdawdfadfasdfadfgadggasdgadhfjkahsdfjgasjdgfjgjhwguyfguagsyudvfvgvaghdsvfghasvdfyeyfyvayevfyuasyudgfjwebjhfve Hgvhgfvawefawefeawppy " ; String T= "Ppy" ; LongStart =System.nanotime ();                System.out.println (Pusuindex (s,t)); LongEnd =System.nanotime (); System.out.println ("Code Execution Time:" + (End-start) + "ns"); }     Public Static intIndexOf (String str,string t) {intm =str.length (); intn =t.length (); if(m-n<0)return-1 ;  for(inti=0;i<m-n+1;i++){            if(Str.charat (i) ==t.charat (0) ) {String temp= Str.substring (i,i+N); if(Temp.equals (t)) {returnI+1 ; }            }        }                return0 ; }         Public Static intPusuindex (String s,string t) {intm =s.length (); intn =t.length (); if(m<n)return-1 ; inti = 0, j = 0 ;  while(i<m&&j<N) {            if(S.charat (i) = =T.charat (j)) {                ++i; + + J;//J is always starting from 0}Else{i= I-j+1 ; J= 0;//J also points to the first of T            }        }        if(j==n)returnI-n + 1 ; Else  return0 ; }}

Pattern matching of string and strings

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.