截取字符串

//截取字符串

-(NSString*)cutString:(NSString*)str

{

NSMutableString*c = [[NSMutableStringalloc]init];

//需要的长度

intposition =4;

for(inti =0; i < str.length; i++){

if(position ==0){

break;

}

unicharch = [strcharacterAtIndex:0];

if(0x4e00< ch&& ch <0x9fff)

{

//若为汉字

[cappendString:[strsubstringWithRange:NSMakeRange(i,1)]];

position = position -2;

}else{

[cappendString:[strsubstringWithRange:NSMakeRange(i,1)]];

position = position -1;

}

}

returnc;

}

你可能感兴趣的:(截取字符串)