Interception of several commonly used strings (Java)

Source: Internet
Author: User

String str= "123abc456";
int i=3;
1 Take the first I character of a string
Str=str. Substring (0,i); or STR=STR. Remove (i,str. LENGTH-I);
2 Remove the first I character of a string:
Str=str.  Remove (0,i); or STR=STR. Substring (i);
3 Take I characters starting from the right:
Str=str. Substring (str. LENGTH-I); or STR=STR. Remove (0,str. LENGTH-I);
4 Remove the I characters starting from the right:
Str=str. Substring (0,str. LENGTH-I); or STR=STR. Remove (str. Length-i,i);
5 Determine if there is "ABC" in the string and remove it
Using System.Text.RegularExpressions;
String str = "123abc456";
String a= "abc";
Regex r = new Regex (a);
Match m = r.match (str);
if (m.success)
{
The green part and the purple part take one kind.
Str=str. Replace (A, "");
Response.Write (str);
String str1,str2;
Str1=str. Substring (0,m.index);
Str2=str. Substring (m.index+a.length,str. Length-a.length-m.index);
Response.Write (STR1+STR2);
}
6 If there is "ABC" in the string, replace it with "ABC"
Str=str. Replace ("abc", "abc");

Interception of several commonly used strings (Java)

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.