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.