首页 > 编程知识 正文

字符串取某个字符开始,js截取字符串后四位

时间:2023-05-03 16:09:27 阅读:51232 作者:4926

33558 www.cn blogs.com/csj 007523/archive/2012/07/15/2592188.html

1 )截取rangeOfString:指定字符串的长度;

2 )截取substringToIndex:7索引到指定索引(7)长度的字符串

3 ) substringFromIndex:9 )剪切从指定索引(9)到末尾长度的字符串

4 ) nsrangerange=nsmakerange (0,7 ); 剪切从指定索引(0)到指定长度的字符串

5 ) substringWithRange:range :剪切从指定索引(0)到指定长度)的字符串

6 ) isequaltostring : @ ' p ://www ' :比较字符串的包含关系,区分大小写

7 ) stringWithFormat:格式字符串。

voidfindSubString (

NSString*filename=@'config.ini ';

ns string * escaped path=@ '/users/config.ini ';

在封装路径中查找文件名

//nsrangeistart=[ escapedpathrangeofstring :文件名称];

nsrangeistart=[ escapedpathrangeofstring 3360文件名选项s 3360 nscaseinsensitivesearch ];

//ns log (@ ' istartlengthis % @ : ),iStart.length );

//ns log (@ ' istartlocationis % @ : ),iStart.location );

if(istart.Length0) {

获取从escapedPath的开始位置到iStart.location-1的长度的子字符串

ns string * substr=[ escapedpathsubstringtoindex : istart.location-1 ];

nslog(@'subStr:%@ ',substr );

获取escapedPath的从iStart.location 1到末尾的子字符串

ns string * extension=[ escapedpathsubstringfromindex : istart.location ]; //之后添加了搜索字符串的长度

nslog(@'extension:%@ ',extension );

ns string * URL=@ ' http://www.seven UC.com ';

nsrangerange=nsmakerange (3,7 );

ns string * prefix=[ urlsubstringwithrange : range ];

nslog(@'prefixis:%@ ',prefix );

if ([ prefixisequaltostring : @ ' p ://www ' )

{

nslog(@'prefixisequal%@ ',prefix );

}

else{

nslog(@'prefixisnotequal%@ ',prefix );

}

获取//URL为0到7个字符的子字符串

if ([ prefixisequaltostring : @ ' http://' )

nslog(@'httpprefixfound );

}

}

void格式字符串(

int文档id=100;

ns string * document filename=@ ' test.doc ';

ns string * requests ring=[ nsstringstringwithformat : @ ' % d % @ '、文档id、文档文件名]

nslog(@'requeststring:%@ ',requestSring );

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。