String string method (using regular expressions to separate strings, filter irrelevant content, output words) __java

Source: Internet
Author: User
Package shiyan4;
public class Lianxi1 {
public static void Main (String args[]) {
String str= "3| Four Rooms (1995) |01-jan-1995| | Http://us.imdb.com (1995) |0|0|0|0|0|1|0|0 ";
Lianxi1_1 (str);
Lianxi1_2 (str);
Lianxi1_3 (str);
}
static void Lianxi1_1 (String str) {
String regex= "[|]";
String words[] =str.split (regex);
SYSTEM.OUT.PRINTLN ("substring in string has:");
for (int i=0;i<words.length; i++) {
System.out.println (Words[i]);

}
}
static void Lianxi1_2 (String str) {
String regex= "[\\s\\d\\p{punct}]+";
String words[] =str.split (regex);
System.out.println ("The words appearing in the string are:");
for (int i=0;i<words.length; i++) {
System.out.println (Words[i]);

}
}
static void Lianxi1_3 (String str) {
int number=0;
System.out.println ("1995 Present Position:");
for (int k=0;k<str.length (); k++) {
if (Str.regionmatches (K, "1995", 0,4)) {
System.out.println (k);
}
}
}
}

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.