objective c - Format text from "HELLO, WORLD. HOW ARE YOU?" to "Hello, world. How are you?" in ObjC(iOS)? -


as title said, need format string of text in format like: "hello, world. how you?" "hello, world. how you?", there standard method doing in ios? or there sample code ?

thanks!

there no direct way capitalize first characters of sentences in paragraph. nsstring has method capitalizedstring capitalizes each , every word. have create own logic achieve this. can try following code.

- (nsstring *)captilizeparagraph:(nsstring *)paragraph {      if ([paragraph length] == 0) return paragraph;     nsarray *sentences = [paragraph componentsseparatedbystring:@". "];     nsmutablearray *capitalizedsentences = [nsmutablearray array];      (nsstring *sentence in sentences) {          sentence = [sentence lowercasestring];         sentence = [sentence stringbyreplacingcharactersinrange:nsmakerange(0,1) withstring:[[sentence substringtoindex:1] uppercasestring]];         [capitalizedsentences addobject:sentence];     }      nsstring *capitalizedparagrah = [capitalizedsentences componentsjoinedbystring:@". "];     return capitalizedparagrah; } 

note: above code assumes sentences in paragraph ends characters ". " (a dot , space) except last sentence(it can end character). if sentence ends other characters "? " or "! ", method return not-fully-formatted string.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -