Truncates two specified strings and two specified strings.

Source: Internet
Author: User

Truncates two specified strings and two specified strings.

For example:

NSString * string = @ "abavavasdsvx, as. dsf/,. [abcdefghijklmn] dgdfg ";

Nsange start = [string rangeOfString: @ "["];
Nsange end = [string rangeOfString: @ "]"];
NSString * sub = [string substringWithRange: NSMakeRange (start. location, end. location-start.location + 1)];

NSLog (@ "sub = % @", sub );

 

Console output: [abcdefghijklmn]

 


How to intercept a string between two specific characters in c #

String stra = "abcdefghijk ";
String strtempa = "c ";
String strtempb = "j ";
// We need a string between c --- g, that is, defghi
// Obtain the positions of strtempa and strtempb:
Int IndexofA = stra. IndexOf (strtempa );
Int IndexofB = stra. IndexOf (strtempb );
String Ru = stra. Substring (IndexofA + 1, IndexofB-IndexofA-1 );
Console. WriteLine ("Ru =" + Ru); // ---- This Is the result you want
Console. ReadLine ();

C # string truncation how do I use a string that contains 1st to 2nd characters

You can use the two functions indexof and substring. The first and second character positions minus the length, starting from the first position.

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.