Android Studio-Interception of several commonly used strings in the 42nd issue

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");


7. How to intercept the characters in front of the specified characters and the following characters in the string

String str = "Key:value:other";

string[] STRs = Str.split (":");

key = Strs[0];

Value = Strs[1];

other = strs[2];


************************************************


String str= "Adcdef"; int indexstart = str. IndexOf ("D");


int EndIndex =str. IndexOf ("E");


string tostr = str. SubString (Indexstart,endindex-indexstart);


C # intercepts the question of the last character of a string!


Str1. Substring (str1. LastIndexOf (",") +1)


This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1949055

Android Studio-Interception of several commonly used strings in the 42nd issue

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.