ios - Why use NSRange on strings when there appears to be a perfectly good substring method? -


i'm learning native ios development first time, , came across struct nsrange. come java background don't see reasoning using range struct when can use substring methods part of nsstring class. advantage of using range structs on using non-range nsstring substring methods.

thanks!

edit: looks considering substring methods: substringfromindex: , substringtoindex:. considering inflexibility of these methods (ie. not being able choose both start , end point) makes range struct instances more necessary. though guess nest 2 methods achieve same result.

edit 2: examples.

non-range substring method examples:

nsstring *str = @"this string.";  nsstring *substr = [str substringtoindex:7];  nsstring *substr2 = [str substringfromindex:7]; 

ranges substring method example:

nsstring *substr3 = [str substringwithrange:nsmakerange(5, 5)]; 

because range based methods offer lot more flexibility, , usable of nsstring search methods (which use ranges heavily). in general, if you're going create substring need know start or end , information have come search, have range.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -