{"id":3175,"date":"2012-03-13T00:30:57","date_gmt":"2012-03-12T19:30:57","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=3175"},"modified":"2025-04-09T12:25:54","modified_gmt":"2025-04-09T12:25:54","slug":"substrings-from-nsstring-n-faq","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/substrings-from-nsstring-n-faq\/","title":{"rendered":"Substrings from NSString"},"content":{"rendered":"<p>Hello iOS geeks &#8230;<a href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2012\/03\/xcode_iphone_simulator.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-3233\" title=\"xcode_iphone_simulator\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2012\/03\/xcode_iphone_simulator.jpg\" alt=\"\" width=\"174\" height=\"144\" \/><\/a><\/p>\n<p>Here is a small tip for getting a substring from NSString;<br \/>\nNSString class provide following methods for\u00a0splitting\u00a0a string;<\/p>\n<p>[sourcecode lang=&#8221;objc&#8221;]<\/p>\n<p>&#8211; (NSString *)substringFromIndex:(NSUInteger)from;<br \/>\n&#8211; (NSString *)substringToIndex:(NSUInteger)to;<br \/>\n&#8211; (NSString *)substringWithRange:(NSRange)range;<br \/>\n&#8211; (NSRange)rangeOfString:(NSString *)&lt;em&gt;aString;&lt;\/em&gt;<br \/>\n[\/sourcecode]<\/p>\n<p>Following code will\u00a0demonstrate\u00a0itself;<\/p>\n<p><!--more--><\/p>\n<p>[sourcecode lang=&#8221;objc&#8221;]<\/p>\n<p>NSString testString = @&#8221;I love programming in objective-c&#8221;;<br \/>\n[testString substringToIndex:5]; \/\/ will return I Love<br \/>\n[testString substringFromIndex:7]; \/\/ will return pogramming in objective-c<br \/>\n[testString substringWithRange:NSMakeRange(21, 32)]; \/\/ will return objective-c<\/p>\n<p>Use this method to check whether the giving string present in the target string or not.<br \/>\n[testString rangeOfString:@&#8221;love&#8221;]; \/\/ Will return an\u00a0NSRange\u00a0structure giving the location and length in the receiver of the first occurrence of\u00a0aString. Returns\u00a0]{NSNotFound, 0}\u00a0if\u00a0=aString\u00a0is not found or is empty (@&#8221;&#8221;).<br \/>\n[\/sourcecode]<\/p>\n<p>I think self descriptive code chunk, so no need to write anything more;\u00a0(:<\/p>\n<p>Happy Development;<\/p>\n<p><em>This post belongs to\u00a0<a href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/category\/knowledge-bank\/n-faq\/\">N-FAQ<\/a>\u00a0category where i post anything i learn new (no matter how its small or big) during my work; N-FAQ = Not-FAQ;<\/em><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/s06.flagcounter.com\/count\/lHF\/bg_FFFFFF\/txt_000000\/border_FFFFFF\/columns_6\/maxflags_248\/viewers_0\/labels_1\/pageviews_1\/flags_0\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello iOS geeks &#8230; Here is a small tip for getting a substring from NSString; NSString class provide following methods for\u00a0splitting\u00a0a string; [sourcecode lang=&#8221;objc&#8221;] &#8211; (NSString *)substringFromIndex:(NSUInteger)from; &#8211; (NSString *)substringToIndex:(NSUInteger)to; &#8211; (NSString *)substringWithRange:(NSRange)range; &#8211; (NSRange)rangeOfString:(NSString *)&lt;em&gt;aString;&lt;\/em&gt; [\/sourcecode] Following code will\u00a0demonstrate\u00a0itself;<\/p>\n","protected":false},"author":1,"featured_media":4555,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[502,512,544,816,819,964,965,966,967],"class_list":["post-3175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","tag-how-to-get-substring-from-nsstring","tag-how-to-split-string-ios","tag-ios","tag-nsrangemake","tag-nsstrng","tag-substring-of-nsstring","tag-substringfromindex","tag-substringtoindex","tag-substringwithrange"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=3175"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3175\/revisions"}],"predecessor-version":[{"id":4556,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/3175\/revisions\/4556"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/4555"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=3175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=3175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=3175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}