1 Public classTestDemo8 {2 3 final static String STARS = "*******************************"; 4 5 Public Static voidMain (string[] args) {6 7String s = "(ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.1.217) (PORT = 1521))";8 intBeginindex = S.indexof ("H");9 intEndIndex = S.lastindexof ("7");TenString news = S.substring (Beginindex, endindex+1); One ASystem.out.println ("s ..." +s); -System.out.println ("Beginindex ..." +beginindex); -System.out.println ("EndIndex ..." +endIndex); theSYSTEM.OUT.PRINTLN ("News ..." +news); - - System.out.println ("Getemail ..." +getemail ("[email protected]"); - } + A Public Staticstring Getemail (string email) { at if(Email = =NULL) -;//Error -string[] Emailparts = Email.split ("@"); - if(Emailparts.length! = 2) -;//Format Error - intLen = emailparts[0].length (); inString char1 = emailparts[0].substring (0, 1); -String char2 = emailparts[0].substring (len-1, Len); to //String char3 = stars.substring (0, len-2); //intercept Intermediate string bits +String CHAR3 = "* * *"; - theSystem.out.println ("1 ..." + emailparts[0]);//Liudehua *System.out.println ("2 ..." + emailparts[1]);//126.com $System.out.println ("Char1 ..." + char1);//LPanax NotoginsengSystem.out.println ("Char2 ..." + char2);//a - the returnchar1+char3+char2+ "@" +emailparts[1]; + } A the}
The output results are as follows:
S ... (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.1.217) (PORT = 1521))
Beginindex ... 28
EndIndex ... 47
News ... HOST = 192.168.1.217
1...liudehua
2...126.com
Char1...l
Char2...a
Getemail...l***[email protected]
The experience of intercepting strings commonly used in Java
Http://jingyan.baidu.com/article/a17d5285224c918098c8f215.html
Intercept string Substitution Chengshing number